VBA: error on saving pdf

Ramon1977

New Member
Joined
Aug 12, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi guys,

I've mad a billing sheet in Excel 365.
When the file is in his orginal map on the PC, there is no problem with exporting to pdf and saving.
However: when I move the file to another map (or computer), saving the bill as .pdf gives an error.
What am I doing wrong?

Ramon

P.s.: some words are dutch:
- factuur = Bill
- Wordt niet meer gebruikt = Isn't used anymore
- Er is iets misgegaan = Error


Private Sub CommandButton2_Click()
MsgBox "WORDT NIET MEER GEBRUIKT"

' On Error GoTo ErrHandler:
' Dim FolderPath As String
'
' FolderPath = Application.ActiveWorkbook.path
' If Right(FolderPath, 1) <> "\" Then
' FolderPath = FolderPath & "\"
' End If
'
' FolderPath = FolderPath & "Facturen"
'
' If Dir(FolderPath, vbDirectory) = vbNullString Then
' MkDir FolderPath
' End If
'
'
' i = 1
' If isEmpty(Range("C13")) Then
' pdfname = "Factuur"
' Else
' pdfname = "Factuur " & Range("C13")
' End If
'
' If Dir(FolderPath & "\" & pdfname & ".pdf") <> "" Then
' Do While Dir(FolderPath & "\" & pdfname & ".pdf") <> ""
'
' If isEmpty(Range("C13")) Then
' pdfname = "Factuur " & " (" & i & ")"
' Else
' pdfname = "Factuur " & Range("C13") & " (" & i & ")"
' End If
'
' i = i + 1
' If i = 100 Then
' Exit Do
' End If
' Loop
' End If
' With ActiveSheet.PageSetup
' .LeftMargin = Application.InchesToPoints(0.1)
' .RightMargin = Application.InchesToPoints(0.1)
' .TopMargin = Application.InchesToPoints(0.3)
' .BottomMargin = Application.InchesToPoints(0.1)
' .HeaderMargin = Application.InchesToPoints(0.1)
' .FooterMargin = Application.InchesToPoints(0.1)
' .CenterHorizontally = True
' .CenterVertically = False
' End With
'
' ActiveSheet.Range("B1:E44").ExportAsFixedFormat Type:=xlTypePDF, Filename:=FolderPath & "\" & pdfname & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
' :=False, OpenAfterPublish:=True
' Exit Sub
'
'ErrHandler:
' MsgBox "Er is iets mis gegaan"
' Resume Next

End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hallo Ramon,

You wan't to save in this subfolder

VBA Code:
FolderPath = FolderPath & "Facturen"

But if you move your file to another directory, your activeworkbook.path is changing too. There probably is no root folder called "Facturen"
 
Upvote 0
Hallo Ramon,

You wan't to save in this subfolder

VBA Code:
FolderPath = FolderPath & "Facturen"

But if you move your file to another directory, your activeworkbook.path is changing too. There probably is no root folder called "Facturen"
Thank you for the answer.
To handle the problem you've mentioned, I wrote the 3 lines below that:

If Dir(FolderPath, vbDirectory) = vbNullString Then
' MkDir FolderPath
' End If

Any ideas, good sir?
 
Upvote 0
What is the error and where in the code is it happening?
 
Upvote 0

Forum statistics

Threads
1,215,108
Messages
6,123,128
Members
449,097
Latest member
mlckr

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