Hi,
I have a button inside Excel workbook which exports certain pages to PDF with one click on a button.
The Excel version I am using is Professional Pro Plus 2019 and my customers version is the same build, but an Office 365 version.
If I hit the button in my version it works, but if my customer does on his computer it gives an Error 52: "Bad file name or number".
More information:
- The file was in a folder in My Documents when tested
- Macro's are enabled at Trust Center
- My customer and I are both working on a Windows PC.
- The code below is in a module
- What the code does is, depending your Choice (ja/nee) on a worksheet, it wil export 1 of 2 sheets to 1 PDF.
Below is the code of the macro I am using:
Does anybody have any idea what the problem might be and what the/a solution is?
Thanks in advance!
Greetings Daan
I have a button inside Excel workbook which exports certain pages to PDF with one click on a button.
The Excel version I am using is Professional Pro Plus 2019 and my customers version is the same build, but an Office 365 version.
If I hit the button in my version it works, but if my customer does on his computer it gives an Error 52: "Bad file name or number".
More information:
- The file was in a folder in My Documents when tested
- Macro's are enabled at Trust Center
- My customer and I are both working on a Windows PC.
- The code below is in a module
- What the code does is, depending your Choice (ja/nee) on a worksheet, it wil export 1 of 2 sheets to 1 PDF.
Below is the code of the macro I am using:
VBA Code:
Sub Maak_offerte()
Dim path_ As String
path_ = ThisWorkbook.Path & "\" & "Offertes"
With CreateObject("Scripting.FileSystemObject")
If Not .FolderExists(path_) Then .CreateFolder (path_)
End With
With Worksheets("OFFERTE").PageSetup
.LeftMargin = Application.CentimetersToPoints(0)
.RightMargin = Application.CentimetersToPoints(0)
.TopMargin = Application.CentimetersToPoints(0)
.BottomMargin = Application.CentimetersToPoints(0)
.Orientation = xlPortrait
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = False
End With
With Worksheets("OHSERVICE").PageSetup
.LeftMargin = Application.CentimetersToPoints(0)
.RightMargin = Application.CentimetersToPoints(0)
.TopMargin = Application.CentimetersToPoints(0)
.BottomMargin = Application.CentimetersToPoints(0)
.Orientation = xlPortrait
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = False
End With
Application.AlertBeforeOverwriting = False
FolderName = "Offertes"
FileName1 = Worksheets("1. STARTGEGEVENS").Range("F16")
FileName2 = Worksheets("2. KLANTGEGEVENS").Range("F16")
FileName3 = Worksheets("2. KLANTGEGEVENS").Range("F14")
Worksheets("OFFERTE").Visible = True
Worksheets("OHSERVICE").Visible = True
If Range("ohservice").Value = "Ja" Then
ThisWorkbook.Sheets(Array("OFFERTE", "OHSERVICE")).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisWorkbook.Path & "\" & FolderName & "\" & FileName1 & " - " & FileName2 & " " & FileName3 & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
Application.AlertBeforeOverwriting = True
Worksheets("OFFERTE").Visible = xlSheetHidden
Worksheets("OHSERVICE").Visible = xlSheetHidden
End If
If Range("ohservice").Value = "Nee" Then
Worksheets("OFFERTE").Visible = True
ThisWorkbook.Sheets(Array("OFFERTE")).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisWorkbook.Path & "\" & FolderName & "\" & FileName1 & " - " & FileName2 & " " & FileName3 & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
Application.AlertBeforeOverwriting = True
Worksheets("OFFERTE").Visible = xlSheetHidden
End If
Worksheets("1. STARTGEGEVENS").Activate
End Sub
Does anybody have any idea what the problem might be and what the/a solution is?
Thanks in advance!
Greetings Daan