Solved

Check in PDF document to SharePoint from Excel using VBA

Posted on 2013-06-11
3
3,957 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

785 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