2

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
Zoe
  • 27,060
  • 21
  • 118
  • 148
Prash
  • 41
  • 2
  • 5
  • 12
  • Can you access the file any other way (e.g. by pasting the url into a web browser)? – z32a7ul Apr 01 '17 at 14:35
  • Are you sure that you want to check in the file at the end of the Sub even if you failed to check it out at the beginning? – z32a7ul Apr 01 '17 at 14:36

3 Answers3

1

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

Leviand
  • 2,745
  • 4
  • 29
  • 43
Joao Ramos
  • 11
  • 1
0

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
ChipsLetten
  • 2,923
  • 1
  • 11
  • 28
-1

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
Community
  • 1
  • 1