Forum

Export Worksheet as...
 
Notifications
Clear all

Export Worksheet as PDF to Sharepoint Folder

4 Posts
2 Users
0 Reactions
571 Views
(@pmcgetti)
Posts: 6
Active Member
Topic starter
 

Hi all - thanks for this wonderful place to learn and gain support.

I developed a Work Request Invoice and used the template code from "VBA to Create PDF from Excel Worksheet Then Email It With Outlook" to make it possible to convert the worksheet into a PDF and populate an Outlook email to be sent. 

I would like to replace the prompt to store it somewhere on my local drive (we're all using PC) and have it automatically seek out a folder on Sharepoint to have the file saved to. 

The Sharepoint "Path" outlined to the preferred destination (Walga Invoices) is: Region 3 CIB > Documents > Contract Support > Walga Invoices

However, the site URL references the original name for the Sharepoint defined by the original name for the Microsoft Teams team that the Sharepoint exists for. That URL is https://usepa.sharepoint.com/sites/OPACIBELMSProcess/Shared%20Documents/Contract%20Support/Walga%20Invoices  

My goal is to have the PDF generated and sent to that Walga Invoices folder - whether the VBA prompts me to save it there or does it automatically doesn't matter to me. 

 

Thanks again, hope there's a solution in sight!

 
Posted : 15/05/2020 8:23 am
(@catalinb)
Posts: 1937
Member Admin
 

Hi Patrick,

Update the following code in your file:

'Create new PDF file name including path and file extension
Dim PDFName As String
PDFName = ActiveSheet.Name & "_" & CurrentMonth & ".pdf"
Dim fs As Object: Set fs = CreateObject("Scripting.FileSystemObject")
PDFFile = DestFolder & Application.PathSeparator & PDFName
fs.CopyFile PDFFile, "\usepa.sharepoint.comsitesOPACIBELMSProcessShared DocumentsContract SupportWalga Invoices" & PDFName

'If the PDF already exists...

Let us know if it works, only you can test it as I guess it's not public.

 
Posted : 15/05/2020 10:26 am
(@pmcgetti)
Posts: 6
Active Member
Topic starter
 

Thanks Catalin - 

When I run this, I get the following error message:

Run-time error '-2147024672 (800700eo)':

Method 'CopyFIle' of object 'IFileSystem3' failed

When I click on Debug it highlights the line: fs.CopyFile PDFFile, "\usepa.sharepoint.comsitesOPACIBELMSProcessShared DocumentsContract SupportWalga Invoices" & PDFName

 
Posted : 15/05/2020 12:01 pm
(@catalinb)
Posts: 1937
Member Admin
 

You need to make sure you can access that folder from your computer.

Try using the folder path in file explorer, see what happens: \usepa.sharepoint.comsitesOPACIBELMSProcessShared DocumentsContract SupportWalga Invoices

You might need to login, then try again the code.

Also, make sure the path is correct

 
Posted : 15/05/2020 12:41 pm
Share: