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

AnthonyMinnaar

New Member
Joined
Aug 25, 2020
Messages
17
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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

AnthonyMinnaar

New Member
Joined
Aug 25, 2020
Messages
17
Office Version
  1. 2013
Platform
  1. Windows
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!
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
37,365
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
It looks like you should have been using backslashes, not forward slashes - eg P:\PO 1\
 
Solution

Forum statistics

Threads
1,141,715
Messages
5,708,052
Members
421,541
Latest member
Akidev

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
Top