run time error 53, file not found

marcenet03

New Member
Joined
Apr 12, 2019
Messages
22
Hello, I have the following macro and used to run perfectly but now isn't working. As it shows run time error 53, file not found. Can someone please help me with what I'm missing?

VBA Code:
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
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
This line is strange and I think may be trying to save the file to a path that does not exists.
VBA Code:
  ThisWorkbook.Path & "\" & CreateObject("Scripting.FileSystemObject").GetFile(ThisWorkbook.FullName).ParentFolder.Name & " XXXQuote ", _

What is your intent for file name and folder name?
 
Upvote 0
the path exists, used to work perfectly. We have multiple projects with customer names. Folder name is customer name and file name is project customer name. Anyhow, used to work fine.
 
Upvote 0
Are you trying to run it on a workbook that has not yet been saved?

Perhaps put this as the first line in that macro and see what it returns
VBA Code:
MsgBox ActiveSheet.Parent.FullName
 
Upvote 0
Are you trying to run it on a workbook that has not yet been saved?

Perhaps put this as the first line in that macro and see what it returns
VBA Code:
MsgBox ActiveSheet.Parent.FullName
 

Attachments

  • Capture.JPG
    Capture.JPG
    17.5 KB · Views: 7
Upvote 0
Sorry then, I'm not sure why it would now be not working.
 
Upvote 0
Any chance you do not have write access?
 
Upvote 0
Does this fail, and if so, on which line of code and for what values of ExportFile and ExportFolder? Does either msgbox appear?
VBA Code:
 Sub printxxx
    Dim ExportFolder As String, ExportFile As String
    Dim strFile As String

    ' Print_quote XXX Macro

    If ThisWorkbook.Path = "" Then
        MsgBox "This workbook (" & ThisWorkbook.Name & ") has not been saved yet and thus has no path.", vbExclamation
        Exit Sub
    End If

    ActiveSheet.PageSetup.Orientation = xlLandscape
    Worksheets("Quote").PageSetup.PrintArea = "$H$6:$Z$133"
    strFile = ThisWorkbook.Path & "\" & strFile

    ExportFile = ThisWorkbook.Path & "\" & CreateObject("Scripting.FileSystemObject").GetFile(ThisWorkbook.FullName).ParentFolder.Name & " XXXQuote "
    Debug.Print ExportFile

    ExportFolder = Left(ExportFile, InStrRev(ExportFile, "\"))
    Debug.Print ExportFolder

    With CreateObject("Scripting.FileSystemObject")
        If Not .FolderExists(ExportFolder) Then
            MsgBox "Folder " & vbCr & vbCr & ExportFolder & vbCr & vbCr & " not found.", vbExclamation
            Exit Sub
        End If
    End With

    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ExportFile, _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, OpenAfterPublish:=True


    ActiveSheet.PageSetup.Orientation = xlPortrait
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,216
Messages
6,123,669
Members
449,114
Latest member
aides

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top