Solved

Check in PDF document to SharePoint from Excel using VBA

Posted on 2013-06-11
3
3,774 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
Comment Utility
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
Comment Utility
Hi,
just verified to code and it works :-)
(at least on my demo machine)
0
 

Author Comment

by:Toucanier
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
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.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now