dimanche 19 avril 2015

Workbook.CheckIn always produces an error the first time it's called?

I have some workbooks stored in a document library on Sharepoint 2007. I want to check out a workbook, modify it, and check it back in.

Using the following code:

Option Explicit

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub test()

Dim bk As Workbook
Dim path As String

path = "http://sharepoint/sites/test/TEST_Relink.xlsm"

If Workbooks.CanCheckOut(path) Then
Application.DisplayAlerts = False
Workbooks.CheckOut path
Set bk = Workbooks.Open(path, False)
bk.Sheets("test").Range("h1").Value = "modified " & Now
Sleep 10000
bk.checkIn True
Application.DisplayAlerts = True
End If

End Sub

The bk.checkIn call always produces the following run-time error:

Method 'CheckIn' of object '_Workbook' failed

After I go into Debug, I press F5 to continue and the check-in always occurs successfully.

I added the 10-second delay with Sleep 10000 because I was thinking that maybe the check-out was taking a while to propagate to the server. But no matter how much time I set for Sleep, this same issue keeps occurring. Any thoughts?

Aucun commentaire:

Enregistrer un commentaire