Check in file on sharepoint using VBA

Spyke831

New Member
Joined
Apr 2, 2009
Messages
23
Hi,the following code fails at - Workbooks(filePath).CheckInwith the following errorrun-time error '9'subscript out of rangeI cant see why this is happening. I am using Excel 2003 and MOSS 2007 (as far as i can tell)<Code>Private Sub ArchiveRecord() Dim RemoveDate As String, filePath As String Unload UserForm1 RemoveDate = Format((Date + 1095), "dd-mmm-yy") Application.ScreenUpdating = False filePath = ThisWorkbook.path & "/Book2.xls" Workbooks.CheckOut filePath Workbooks.Open (filePath) Workbooks(ThisWorkbook.Name).Sheets("Test1").Copy After:=Workbooks("Book2.xls").Sheets("Sheet1") ActiveSheet.Name = ActiveSheet.Name & " (Delete on " & RemoveDate & ")" Workbooks(filePath).CheckIn Application.ScreenUpdating = TrueEnd Subany help greatly received.Matt
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I had LOADS of trouble with checking in before I discovered a very odd way to get around it.
1. I made sure that I made a change to the workbook (but not one that altered any data. The one I always found successful was to do a column AutoFit thus:
Code:
Range("A:A").EntireColumn.AutoFit
It didn't seem to matter as to which column I applied the command to - just that it worked.

2. In my particular application, as the CheckIn was on the Active Workbook (which would obviously close it) I made sure that
Code:
ActiveWorkbook.Checkin
was the last line in my procedure.

I don't know WHY 1. works - I just know that it does!

Hope this helps

Pete

P.S. On here, don't forget to begin and end your code with HTML tags, to make it read more clearly.
OpenSquareBracket ([) followed by the word "code" (not in quotes) + CloseSquareBracket (])
THEN YOUR CODE
followed by:
OpenSquareBracket ([) + "/code" (not in quotes) + CloseSquareBracket (])
 
Last edited:
Upvote 0
Pete,Thanks for the reply, I now get the following error - Runtime Error '1004' Method 'CheckIn of object '_Workbook' failed. The altered code is below. (Thanks for the code tip for posts too).
Code:
Private Sub ArchiveRecord()Dim RemoveDate As String, filePath As StringUnload UserForm1RemoveDate = Format((Date + 1095), "dd-mmm-yy")Application.ScreenUpdating = FalsefilePath = ThisWorkbook.path & "/Book2.xls"Workbooks.CheckOut filePathWorkbooks.Open (filePath)Workbooks(ThisWorkbook.Name).Sheets("Test1").Copy After:=Workbooks("Book2.xls").Sheets("Sheet1")ActiveSheet.Name = ActiveSheet.Name & " (Delete on " & RemoveDate & ")"Application.ScreenUpdating = TrueActiveWorkbook.CheckInEnd Sub
Thanks for the helpMatt
 
Upvote 0
Private Sub ArchiveRecord()
Dim RemoveDate As String, filePath As String
Unload UserForm1
RemoveDate = Format((Date + 1095), "dd-mmm-yy")
Application.ScreenUpdating = False
filePath = ThisWorkbook.path & "/Book2.xls"
Workbooks.CheckOut filePath
Workbooks.Open (filePath)
Workbooks(ThisWorkbook.Name).Sheets("Test1").Copy After:=Workbooks("Book2.xls").Sheets("Sheet1")
ActiveSheet.Name = ActiveSheet.Name & " (Delete on " & RemoveDate & ")"
Application.ScreenUpdating = True
ActiveWorkbook.CheckIn
End Sub
 
Upvote 0
I AM looking at this - unfortunately, I've just locked up a critical workbook during my testing, so may be a little while coming back to you with a solution!
 
Upvote 0
Good afternoon, Spyke,
See if you can make use of any of my solution below which checks if something can be checked out before doing so, then checks if it can be checked back in again, before doing so.

Code:
'The MyWorkbook variable MUST be declared outside CheckItOut and CheckItIn to make it available to both.
Public MyWorkbook As Workbook


Sub CheckItOut()
    
    Dim FilePath As String
    Dim MasterWorkbook As String
    
    On Error GoTo ErrorCheckOut
    
    MasterWorkbook = ActiveWorkbook.Name
    FilePath = "\\SharePoint\Sites\Dev\Build\BR\Project Plans\BRP-004 Product Database (ALL)\01 Project Plan\Test Workbook.xlsm"
    
    If Workbooks.CanCheckOut(FilePath) = True Then
        MsgBox (FilePath & Chr(10) & Chr(10) & "CAN be checked out.")
        Workbooks.CheckOut FilePath                 'Check out workbook
        Set MyWorkbook = Workbooks.Open(FilePath)   'Open workbook & set MyWorkbook variable to allow CheckIn by CheckItIn proc.
        Workbooks(MasterWorkbook).Activate          'Reactivate caller workbook
        Exit Sub
    Else
        MsgBox (FilePath & Chr(10) & Chr(10) & "can NOT be checked out at this time. Please try again later.")
        Exit Sub
    End If
    
ErrorCheckOut:
    MsgBox ("A CheckOut error occurred!")

End Sub


Sub CheckItIn()
    
    On Error GoTo ErrorCheckIn
    
    MyWorkbook.Sheets("Sheet1").Range("A1").EntireColumn.AutoFit
    
    'The workbook's name was stored to "MyWorkbook" by CheckItOut - this variable is now used to check the workbook back in.
    If MyWorkbook.CanCheckIn = True Then
        MsgBox (MyWorkbook.Name & Chr(10) & Chr(10) & "CAN be checked in.")
        MyWorkbook.CheckIn                          'Check in workbook
        Exit Sub
    Else
        MsgBox (MyWorkbook.Name & Chr(10) & Chr(10) & "can NOT be checked in at this time. Please try again later.")
        Exit Sub
    End If

ErrorCheckIn:
    MsgBox ("A CheckIn error occurred!")

End Sub
 
Upvote 0
Thanks Pete I will try this as soon as I get back into work tomorrow<BR>and let you know the outcome<br> Spyke
 
Upvote 0

Forum statistics

Threads
1,215,453
Messages
6,124,925
Members
449,195
Latest member
Stevenciu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top