View Full Version : VBA To convert Sharepoint page to PDF

2016-09-11, 09:03 AM
Hello Gurus,

I am looking to tweak a code which converts a webpage to PDF and store it in a specific directory.

This solution (http://stackoverflow.com/questions/33900668/saving-webpage-as-pdf-to-certain-directory) is exactly what I am looking for but unfortunately this is not working in a "Share point environment".

Sub WebSMacro()

'set default printer to AdobePDF
Dim WSHNetwork As Object
Set WSHNetwork = CreateObject("WScript.Network")
WSHNetwork.SetDefaultPrinter "Adobe PDF"

'get pdfSave as Path from cell range
Dim sFolder As String
sFolder = Sheets("Sheet1").Range("A1") 'assumes folder save as path is in cell A1 of mySheets

Dim IE As Object
Dim Webloc As String
Dim FullWeb As String

Webloc = ActiveSheet.Range("B39").Value
FullWeb = "https://asharepointsiteurl.aspx" & Webloc
Set IE = CreateObject("InternetExplorer.Application")

With IE

.Visible = True
.Navigate FullWeb

Do While .Busy
Application.Wait DateAdd("s", 1, Now)

Application.Wait DateAdd("s", 3, Now)
Call PDFPrint(sFolder & Webloc & ".pdf")


End With

Set IE = Nothing

End Sub

I am getting the error in .ExecWB method(6,2 params should print the page without the dialog box ,which is working fine for all normal websites)

Can someone advice what is wrong here ? Is this something to do with the load time of the page?