Mrrrr's Forum (VIEW ONLY)
Un forum care ofera solutii pentru unele probleme legate in general de PC. Pe langa solutii, aici puteti gasi si alte lucruri interesante // A forum that offers solutions to some PC related issues. Besides these, here you can find more interesting stuff.
|
Nou pe simpatie: Aandreea
 | Femeie 24 ani Bucuresti cauta Barbat 25 - 52 ani |
|
|
Mrrrr's Forum (VIEW ONLY)ReguliInregistrareLoginPozeNu sunteti logat. Lista Forumurilor Pe Tematici
|
| #1 |
TRaPModerator
Postari: 960
|
|
Pressing a button linked to the following code will open an InputBox asking for the desired file name, then after pressing OK the file will be saved to desktop.
Source for getting special folder path using VBA: http://learnexcelmacro.com/wp/2012/12/g ... cel-macro/ Rest was done with macro recorder.
Sub FileSaveToDesktop()
Dim FileName As String Dim objSFolders As Object Dim FilePath As String Set objSFolders = CreateObject("WScript.Shell").SpecialFolders
FilePath = objSFolders("desktop")
FileName = InputBox("Enter file name and press OK to save it to Desktop as xlsx file")
ActiveWorkbook.SaveAs FileName:= _ FilePath & "\" & FileName & ".xlsx", FileFormat:= _ xlOpenXMLWorkbook, CreateBackup:=False End Sub
|
|
|
| |
|
| #2 |
|
|
Another option to get to the desktop would be by using:
| Environ("USERPROFILE") & "\Desktop\" |
but this sometimes has issues with OneDrive desktop. I will save the file to the "old" / "normal" Desktop instead of using the OneDrive Desktop.
_______________________________________

|
|
| |
|
| #3 |
|
|
This is the best method that I found so far that addresses the OneDrive desktop "issue" and saves in there:
savePath = CreateObject("WScript.Shell").SpecialFolders("Desktop") & Application.PathSeparator
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ savePath & ActiveSheet.Range("A2").Value & " - " & Format(Date, "dd.mm.yyyy") & ".pdf", _ Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False |
_______________________________________

|
|
| |
|
| #5 |
TRaPModerator
Postari: 960
|
|
Code to save specific sheet if sheet name is something specific (can be updated to use sheet name only from specific file too) with certain data extracted from said sheet, and all other sheets from any other document with current time in file name.
Sub Save_As_PDF() Application.ScreenUpdating = False Application.PrintCommunication = False
Dim ws As Worksheet Set ws = ActiveSheet If ActiveSheet.Name = "SPECIFIC_SHEET_NAME" Then ActiveSheet.ExportAsFixedFormat 0, _ CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\" & _ ws.Range("C5").Value & "-" & _ ws.Range("I2").Value & "-" & _ "F.01.04.77" & "-" & _ ws.Range("C7").Value & "-" & _ Replace(ws.Range("C8").Value, "*", "X") & "-" & _ ws.Range("C6").Value & _ ".pdf", _ Quality:=xlQualityStandard, _ IncludeDocProperties:=True, _ IgnorePrintAreas:=False, _ From:=1, _ OpenAfterPublish:=False ' To:=1 ' ca sa listeze doar pagina 1 la 1; fara To, salveaza tot ce e vizibil Else ActiveSheet.ExportAsFixedFormat 0, _ CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\" & ActiveSheet.Name & " - " & Format(Now, "hh.mm.ss") & ".pdf", _ Quality:=xlQualityStandard, _ IncludeDocProperties:=True, _ IgnorePrintAreas:=False, _ From:=1, _ OpenAfterPublish:=False ' To:=1 ' ca sa listeze doar pagina 1 la 1; fara To, salveaza tot ce e vizibil
End If Application.PrintCommunication = True Application.ScreenUpdating = True End Sub |
|
|
| |
|
| #6 |
TRaPModerator
Postari: 960
|
|
ChatGTP suggestion to not use VBA: add a button to QAT from All Commands: Publish PDF or XPS.
|
|
| |
|