Prash
Prash

Reputation: 41

Checkout and checkin sharepoint file

I am getting Runtime error 1004: cancheckout method failed near cancheckout and

Compile error: Method or data member not found in line

If Workbooks.CanCheckIn(ChkFile) = True Then

How do I resolve the issue?

Sub ToCheck()
    Dim xlApp As Excel.Application
    Dim wb As Workbook
    Dim ChkFile As String
    ChkFile = "http://new1....com/Shared%20Documents/file.xlsm"

    If Workbooks.CanCheckOut(ChkFile) = True Then 'getting error here
        Workbooks.CheckOut ChkFile

        Set xlApp = New Excel.Application
        xlApp.Visible = True

        Set wb = xlApp.Workbooks.Open(ChkFile, , False)
    End If

    ThisWorkbook.Activate
    Application.Run ("'file.xlsm'!Macro1")

    ThisWorkbook.Save

    Workbooks(ChkFile).Activate

    If Workbooks.CanCheckIn(ChkFile) = True Then 'Getting error here
        Workbooks(ChkFile).CheckIn
    End If
End Sub

Upvotes: 2

Views: 12438

Answers (3)

ChipsLetten
ChipsLetten

Reputation: 2953

The CanCheckIn method belongs to an individual Workbook object. You are trying to use it from the Workbooks collection.

Try using this code:

If Workbooks(ChkFile).CanCheckIn = True Then

Upvotes: 0

Joao Ramos
Joao Ramos

Reputation: 11

Try changing ChkFile = "http://new1....com/Shared%20Documents/file.xlsm" to ChkFile = "http://new1....com/Shared Documents/file.xlsm", i.e. replacing %20 for a space since the whole path is already within brackets

Upvotes: 1

excelexpert
excelexpert

Reputation: 11

I tried a lot of way to resolve this, finally this method worked for me

Dim URL as String
Dim wb as Workbook

URL = "http://your.com/path/to/doc.xlsx"          

If Workbooks.CanCheckOut(URL) = True Then
    Workbooks.CheckOut URL
    Set wb = Workbooks.Open(URL, , False)
Else
    MsgBox ("Unable to checkout document")
End If

Upvotes: -1

Related Questions