Solved

Check in PDF document to SharePoint from Excel using VBA

Posted on 2013-06-11
3
4,254 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

707 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