error when exporting PDF with vba code because of space in path

AnthonyMinnaar

New Member
Joined
Aug 25, 2020
Messages
28
Office Version
  1. 2013
Platform
  1. Windows
Hi folks,

I used the following code to export a sheet to pdf using a cell to set the path and file name. problem is, when the path contains a space, it'll give an error. it works of the path doesn't contain an space.

-----------------------------------------------------------------------------------------------
Sub SaveAsPDF_Click1()

Dim FileAndLocation As Variant
Dim strPathLocation As String
Dim strFilename As String
Dim strPathFile As String

strPathLocation = Worksheets("invulsheet").Range("I2").Value
strFilename = Worksheets("invulsheet").Range("I5").Value
strPathFile = strPathLocation & strFilename

Sheets("1").Select

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
strPathLocation & strFilename & ".pdf" _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False

End Sub
-----------------------------------------------------------------------------------------------


value in cell I2 = P:/PO 1/ (if I remove the space it works fine, but the directory needs to contain a space)

is there a solution to his?

thanks in advance!

Anthony.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
found the solution, works if a make it so I can pick a location from the browser. not sure why this works, but it does!
 
Upvote 0
It looks like you should have been using backslashes, not forward slashes - eg P:\PO 1\
 
Upvote 0
Solution

Forum statistics

Threads
1,214,424
Messages
6,119,401
Members
448,893
Latest member
AtariBaby

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