Excel VBA code to export sheet as PDF into SharePoint folder

kaufa

New Member
Joined
Sep 27, 2022
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hello everyone,

I am kindly requesting support from you guys as I am struggeling to make this VBA code work.

I would like it to save the active sheet as a PDF onto a SharePoint folder, but I always get the following error message :

Capture1.PNG


VBA Code:
Sub ExportDashboardToPDF()

    Dim PathName As String

    Dim FileName As String

    PathName = "//sites.company.com/sites/OurTeam/Shared%20Documents/General/"
    
    FileName = Format(Date, "yyyy-mm-dd") & "_ExcelFileName" & ".pdf"

    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=PathName & FileName _
    , Quality:=xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas _
        :=False, OpenAfterPublish:=False

End Sub

I have full access to our SharePoint environement and if I try to save it with the 'save as copy' Excel option, it works. I guess the issue might come from the format I want to apply to the filename.

Thank you very much in advance for your support !
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hello everyone,

I am kindly requesting support from you guys as I am struggeling to make this VBA code work.

I would like it to save the active sheet as a PDF onto a SharePoint folder, but I always get the following error message :

View attachment 76121

VBA Code:
Sub ExportDashboardToPDF()

    Dim PathName As String

    Dim FileName As String

    PathName = "//sites.company.com/sites/OurTeam/Shared%20Documents/General/"
   
    FileName = Format(Date, "yyyy-mm-dd") & "_ExcelFileName" & ".pdf"

    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=PathName & FileName _
    , Quality:=xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas _
        :=False, OpenAfterPublish:=False

End Sub

I have full access to our SharePoint environement and if I try to save it with the 'save as copy' Excel option, it works. I guess the issue might come from the format I want to apply to the filename.

Thank you very much in advance for your support !

Hi again,

Seems I found the issue : 'https:' was missing from the pathname and with it added to the code, it works perfectly !

Regards
 
Upvote 0
Solution

Forum statistics

Threads
1,223,893
Messages
6,175,246
Members
452,623
Latest member
cliftonhandyman

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