locked
Cannot programatically checkin Excel document RRS feed

  • Question

  • I have a macro in the workbook that I am working in. The macro checks out a different spreadsheet (that I will want to make changes to) and then should check it back in. I am including the code from the macro below. When I run the macro, it checks out the file and opens it. It then proceeds to the checkin subroutine, but fails with the message run-time error 1004 "Method 'CheckIn' of object '_Workbook' failed. I tried fully qualifying the checkin, but have the same results.

    Any assistance would be greatly appreciated!

    Mike

     

     

    Option Base 1
    Public wb0 As Workbook
    Public xlFile0 As String
    Public FileName0 As String
    
    Sub Automation_Vetting_Process()
     xlFile0 = "http:// ..." 'Actual SharePoint URL
     CheckoutFile (xlFile0)
     FileName0 = wb0.Name
     CheckinFile (FileName0)
    End Sub
    
    Sub CheckoutFile(FileName As String)
    ' Determine if workbook can be checked out
     If Application.Workbooks.CanCheckOut(xlFile0) Then
     Application.Workbooks.CheckOut xlFile0
     Set wb0 = Application.Workbooks.Open(xlFile0)
     MsgBox wb0.Name & " is checked out to you."
     Else
     MsgBox "You are unable to checkout the at this time."
     End If
    End Sub
    
    Sub CheckinFile(FileName As String)
    ' Determine if workbook can be checked in
     If Application.Workbooks(FileName).CanCheckIn = True Then
     Application.Workbooks(FileName).CheckIn SaveChanges:=True, Comments:="", MakePublic:=False
     MsgBox FileName & " was checked in."
     Else
     MsgBox "You are unable to checkin the " & FileName & " spreadsheet at this time."
     End If
    End Sub


    • Edited by Mike Walsh FIN Monday, June 27, 2011 4:12 PM Pressure removed - in forums just ask the question
    • Moved by Mike Walsh FIN Monday, June 27, 2011 4:13 PM programmatically means the programming forum NOT general (From:SharePoint - General Question and Answers and Discussion (pre-SharePoint 2010))
    Monday, June 27, 2011 3:00 PM

All replies

  • Hi

    The  CanCheckIn property determines whether Microsoft Office Word can check in the document to a server. But if you document is checkout by another user OR you don't have the version control enable in Sharepoint , it will fail.

    Cheers

     


    Gabriel Renom - Business Systems Analyst - Pannone LLP - Blog: www.gabrielrenom.net
    Tuesday, September 20, 2011 11:23 AM
  • Hi,

    I am in agreement with gabriel.

    before performing any operation first check if the file is already checked out or not.

    You can use SPFile.CheckOutType property for the same.

    I hope this will help you out.


    Thanks, Rahul Rashu
    Wednesday, September 21, 2011 5:49 AM