VBA Code Runtime error 5

sintek

New Member
Joined
Oct 14, 2015
Messages
39
Hi All

I have been searching the web to no avail for a solution. Have also posted on ExcelForum with no results. Perhaps someone on this forum can help me solve my problem.
I have the below code which works perfectly on my PC...Running windows 7 - Excel 2007. When I try to run on another PC - also Excel 2007 - On Windows XP platform though, taking the new Path into account I get a Error - Runtime error 5 Invalid procedure or call argument. The code it stops at within below code is:

Code:
ws.ExportAsFixedFormat 0, fNAME


Code:
Private Sub CommandButton9_Click()
    Dim FolderPath As String, ws As Worksheet
    Dim fNAME As String, WbName As String
    
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    
    WbName = ActiveSheet.Range("D5") & " " & ActiveSheet.Range("E5")
    FolderPath = "C:\Documents and Settings\La Belle Motors\Desktop\PAYSLIPS\" & ActiveSheet.Range("g6")
  
    On Error Resume Next
    MkDir FolderPath
    MkDir FolderPath & "\" & WbName
    On Error GoTo 0
    
    For Each ws In ActiveWorkbook.Worksheets
        If ws.Name <> Sheet1.Name And ws.Name <> Sheet3.Name Then
            fNAME = FolderPath & "\" & WbName & "\" & ws.Name & ".pdf"
            ws.ExportAsFixedFormat 0, fNAME
        End If
    Next ws
    
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
       
End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,214,599
Messages
6,120,448
Members
448,966
Latest member
DannyC96

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