Solved

Check in PDF document to SharePoint from Excel using VBA

Posted on 2013-06-11
3
4,027 Views
Last Modified: 2015-08-20
Hi

Can anyone post some simple vba code that I can plug in to my own code to allow me to automatically check in PDF files that have just been automatically created and saved on a SharePoint site?

I'm using the simple procedure, below, which works but means that I have the inconvenience of having to do manual check-ins afterwards.

Sub SaveAsPDF(ByVal theFileName As String, theID As String)

    Dim myPath As String
        
    Sheets(theID).Select
    
    myPath = Range("IssueDefectPath") & theFileName & ".pdf"
    
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=myPath, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
   
    ActiveWorkbook.Save
    
End Sub

Open in new window

0
Comment
Question by:Toucanier
  • 2
3 Comments
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
ID: 39238578
Hi,
you will have to call a SharePoint web service.
http://msdn.microsoft.com/en-us/library/lists.lists.checkinfile%28v=office.12%29.aspx

Code sample:
    Dim sURL As String
    Dim sEnv As String
    Dim xmlhtp As New MSXML2.XMLHTTP
    Dim xmlDoc As New DOMDocument
	Dim sDocumentPath As String
	Dim sComment As String
    Dim sCheckInType As String
	Dim sHostSetting As String
	'SET YOUR VALUES INTO XXX
	' Set here the SharePoint site url where the library is in
    sURL = "https://xxx/_vti_bin/lists.asmx"
	' Set here the complete document path
	sDocumentPath = "https://xxx/yyy/document.pdf"
	' Set a checkin comment if wanted
	sComment = "Checked in from Excel"
	' Set the checkin type (see http://msdn.microsoft.com/en-us/library/lists.lists.checkinfile%28v=office.12%29.aspx)
	' A string representation of the values 0, 1 or 2, where 0 = MinorCheckIn, 1 = MajorCheckIn, and 2 = OverwriteCheckIn.
	sCheckInType = "1"
	' Set the host name to the root url without the protocol (e.g. sharepoint.myapp.com)
	sHostSetting = "xxx.yyy.com"
	
    sEnv = "<?xml version=""1.0"" encoding=""utf-8""?>"
    sEnv = sEnv & "<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">"
    sEnv = sEnv & "  <soap:Body>"
    sEnv = sEnv & "    <CheckInFile xmlns=""http://schemas.microsoft.com/sharepoint/soap/"">"
    sEnv = sEnv & "      <pageUrl>" & sDocumentPath & "</pageUrl>"
    sEnv = sEnv & "      <comment>" & sComment & "</comment>"
    sEnv = sEnv & "      <CheckinType>" & sCheckInType & "</CheckinType>"
    sEnv = sEnv & "    </CheckInFile>"
    sEnv = sEnv & "  </soap:Body>"
    sEnv = sEnv & "</soap:Envelope>"

    With xmlhtp
        .Open "post", sURL, False
        .setRequestHeader "Host", sHostSetting
        .setRequestHeader "Content-Type", "text/xml; charset=utf-8"
        .setRequestHeader "soapAction", "http://schemas.microsoft.com/sharepoint/soap/CheckInFile"
        .send sEnv
        xmlDoc.LoadXML .responseText
    End With
    MsgBox "Done"

Open in new window


I could not yet test the code, but it should work.

HTH
Rainer
0
 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 39238640
Hi,
just verified to code and it works :-)
(at least on my demo machine)
0
 

Author Comment

by:Toucanier
ID: 39243821
Thanks very much for this. I only needed to tweak a few variables and it worked perfectly. This will save me many hours of mundane work when automatically creating PDFs.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question