VBA Excel Error Run-Time error 53-file not found - excel

this code used to run perfectly now is having time error 53, file not found. Not sure what is wrong
Sub printxxx()
' Print_quote XXX Macro
ActiveSheet.PageSetup.Orientation = xlLandscape
Worksheets("Quote").PageSetup.PrintArea = "$H$6:$Z$133"
strFile = ThisWorkbook.Path & "\" & strFile
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Path & "\" & CreateObject("Scripting.FileSystemObject").GetFile(ThisWorkbook.FullName).ParentFolder.Name & " XXXQuote ", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
ActiveSheet.PageSetup.Orientation = xlPortrait
End Sub

Related

Run Time Error 5 when Running the macro from a shared drive

The following code runs perfectly from my desktop or other folder paths. Except in a shared drive that keeps giving me a run-time error 5
The error appears on the following line
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Path & "\" & Cell & ".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
The full code
Private Sub CommandButton1_Click()
Dim ReportSheet As Worksheet
If ThisWorkbook.Worksheets("Cover Page").Range("F11").Value <> vbNullString Then
FormatDate = Format(Sheets("Cover Page").Range("F11"), "MMMM DD, YYYY")
End If
Cell = "Statements - " & FormatDate
ThisWorkbook.Sheets(Array("Sheet1", " Sheet2", " Sheet3”).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Path & "\" & Cell & ".pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
Application.Goto Reference:=Sheets("X").Range("A1")
End Sub

Exporting multiple sheets to PDF and getting run time error VBA

I keep getting RunTime error of '(2147024773)8007007b' everytime I execute the macro, I don't know what I have done wrong. Any hints on how to fix this?
Dim wsA As Worksheet
Set wsA = ActiveSheet
Sheets("Main_Page").Activate
ActiveSheet.Range("A01:F30").Select
Sheets("Sheet3").Activate
ActiveSheet.Range("A01:B6").Select
Sheets(Array("Sheet1", "Sheet3")).Select
Selection.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=ActiveWorkbook.Path & "\" & strFilename & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End Sub
I don't see you creating the variable and assigning a value to it you can try this. Also try avoiding select and activate.
Sub SaveMultipleSheetsAsPDF()
Dim strFilename As String
Dim sht1 As Range
Dim sht3 As Range
Set sht1 = Worksheets("Main_Page").Range("A1:F30")
Set sht3 = Worksheets("Sheet3").Range("A1:B6")
strFilename = "mySheets"
sht1.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=ActiveWorkbook.Path & "\" & strFilename & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
sht3.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=ActiveWorkbook.Path & "\" & strFilename & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
End Sub

VBA Excel on Mac: Print / Export to PDF

I have this huge excel file with macros, it works perfectly on windows, but on MacOs it gives me an error 1004. Can somebody help me to translate following code so that it works on Macos? Or actually, can somebody translate it to work on Excel (Macos), because I have absolute no understanding of coding. If somebody can help me with this, I don't have to install Windows to my Mac :)
Sub SaveAsPdf(train)
'On Error Resume Next
'Windows(ThisWorkbook.Name).Activate
Application.Goto reference:="date"
days = Year(ActiveCell.Value) & Month(ActiveCell.Value) & Day(ActiveCell.Value)
Application.Goto reference:="path"
Path = ActiveCell.Value
If Right(Path, 1) <> "\" Then
Path = Path & "\"
End If
ws = "Train " & train & " Production schedule"
Sheets(ws).Select
Time_Stamp = Format(Now(), "yyyymmdd_HhNn")
TNimi = Path & ws & Time_Stamp & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
TNimi, Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
ws = "General Schedule " & train
fname = "General Schedule Train " & train
Sheets(ws).Select
Time_Stamp = Format(Now(), "yyyymmdd_HhNn")
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
Path & fname & "_" & Time_Stamp & ".pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Sheets("Break Plan Input").Select
End Sub
Sub SaveQSheet(train)
Sheets("Break Plan Input").Select
Application.Goto reference:="date"
days = Year(ActiveCell.Value) & Month(ActiveCell.Value) & Day(ActiveCell.Value)
Application.Goto reference:="path"
Path = ActiveCell.Value
If Right(Path, 1) <> "\" Then
Path = Path & "\"
End If
Time_Stamp = Format(Now(), "yyyymmdd_HhNn")
Sheets("Inspection and Sold Info").Select
Sheets("Inspection and Sold Info").Copy
Range("A2").Select
ActiveWorkbook.SaveAs Filename:=Path & "Train " & train & " Inspection and Sold Info " & Time_Stamp & ".xlsx", _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWindow.Close
Sheets("Break Plan Input").Select
End Sub
Path defined

Save range of cells to PDF at ThisWorkbook.Path

I have this macro that saves to a defined path which is not useful since multiple people will be using the file.
Sub SavetoPdf()
'
' SavetoPdf Macro
' To Save to PDF Details
'
' Keyboard Shortcut: Ctrl+s
'
Range("E31:I54").Select
Application.CutCopyMode = False
ChDir "/Users/Me/Desktop/"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
"/Users/Me/Desktop/" & Range("G41").Value & ".pdf", Quality:=xlQualityMinimum, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
End Sub
I thought to save to ThisWorkbook.Path and modified the above.
Sub SavetoPdf()
' Saves active sheet as PDF file.
Dim Name As String
Name = ThisWorkbook.Path & "/" & Range("G41").Value & ".pdf"
Range("E31:I54").Select
Application.CutCopyMode = False
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=Name, _
Quality:=xlQualityMinimum, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End Sub
I am on a Mac.
I get
Error on Printing
and the debugger highlights this code:
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=Name, _
Quality:=xlQualityMinimum, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
You title reads that you want to PDF a "Range" of cells. Is that what is not working for you?
Sub SavetoPdf()
' Saves active sheet as PDF file.
Dim Name As String
Name = ThisWorkbook.Path & "/" & Range("G41").Value & ".pdf"
Range("E31:I54").ExportAsFixedFormat Type:=xlTypePDF, Filename:=Name, _
Quality:=xlQualityMinimum, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End Sub
Modified #Davesexel code: Tested on mock data and saved no problem.
Dim rng As Range
Dim Name As String
Set rng = Worksheets("Sheet1").Range("G41") 'Change worksheet to your needs
Name = rng.Value
Range("E31:I54").ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=ThisWorkbook.Path & "/" & Name & ".pdf", _
Quality:=xlQualityMinimum, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=False

Save PDF file automatically in new folder

I have the following macro to create a folder within the folder where the Excel file is:
Sub Folder_Test()
If Dir(ThisWorkbook.Path & "\" & "Folder_01", vbDirectory) = "Folder_01" Then
MsgBox "Folder already exists!"
Else
MkDir Application.ThisWorkbook.Path & "\" & "Folder_01"
End If
End Sub
And I have the following macro to create a PDF file:
Sub Button_PDF_200()
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Path & "\" & "test.pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
End Sub
Now I want that the PDF file which is created in the second macro will be saved in the folder which is created in the first macro.
Do you have any idea how I can do this?
Maybe just that?
Sub Button_PDF_200()
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
ThisWorkbook.Path & "\" & "Folder_01" & "\" & "test.pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
End Sub
That is changing the Filename argument within the sub Button_PDF_200 from
ThisWorkbook.Path & "\" & "test.pdf"
to
ThisWorkbook.Path & "\" & "Folder_01" & "\" & "test.pdf"
..
Hi Michi,
also you can try something like this:
pdfName = ActiveSheet.Range("T1")
ChDir "C:\Temp\" 'This is where youo set a defult file path.
fileSaveName = Application.GetSaveAsFilename(pdfName, _
fileFilter:="PDF Files (*.pdf), *.pdf")
If fileSaveName <> False Then
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, fileName:= _
fileSaveName _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True
End If
MsgBox "File Saved to" & " " & fileSaveName
Have fun!

Resources