method open of object workbooks failed

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,392
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
While working on a spreadsheet at work, I was getting the error "method open of object workbooks failed", but when I got home, the same file was not giving me any errors. Any ideas why?
 
I copied the quoting tool file and the file that the rows get transferred too, onto a common drive on the server that everyone has access to and it does the same thing.
 
Upvote 0

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Did you change the code, as suggested ??
AND
Do the variables reflect the correct locations on that common drive ?
If there is still a problem, I'd talk to your IT !
 
Last edited:
Upvote 0
Is your laptop and work using the same versions of windows AND excel ??
 
Upvote 0
  1. Work has Microsoft office professional plus 2016 and I have Microsoft office 365 but I thought that they would be compatible.
  2. They both are running windows 10
  3. I tried to comment out the code enableevents=true but that did nothing.
  4. At the end, I noticed that the code in the With Application is slightly different to the code within the With Application at the beginning, would that make a difference?
  5. They appear to reflect the locations on the network drive.
 
Upvote 0
I can only suggest then that the versions have a compatibility problem.
Another thing to try would to move the code out of the sheet module.....it shouldn't be there anyway !!...put it in the Thisworkbook module
AND
Might be meaningless, but change the line of code to
Code:
Workbooks.Open Filename:=Activeworkbook.Path & "\" & DocYearName
Check with IT to see if there have been any addins installed, and if so get them turned off and retest....otherwise I can' really help you !!
 
Upvote 0
Thanks for trying Michael.

I tried to move it out and put it in the thisworkbook module and then I got an error with the selection of the button that called the procedure and it says sub or function not defined.
 
Last edited:
Upvote 0
I just copied cmdCopy into the thisworkbook module and in the sheet 10 module, I included call cmdCopy in the code and that was where it said the sub was not defined. What else do I need to do?
 
Last edited:
Upvote 0
Does DocYearName include the file extension?

Does this work any better?
Code:
Option Explicit

Sub cmdCopy()
Dim wbDst As Workbook
Dim wsDst As Worksheet, wsSrc As Worksheet, tblrow As ListRow
Dim Combo As String, sht As Worksheet, tbl As ListObject
Dim LastRow As Long, lr As Long, DocYearName As String
Dim WbName As String, Workbook As Workbook
    With Application
    
        .Calculation = xlCalculationManual
        .ScreenUpdating = False
        .DisplayAlerts = False
        .EnableEvents = False
    End With


    'assign values to variables
    Set tbl = ThisWorkbook.Worksheets("Costing_tool").ListObjects("tblCosting")

    For Each tblrow In tbl.ListRows
        If tblrow.Range.Cells(1, 1).Value = "" Or tblrow.Range.Cells(1, 5).Value = "" Or tblrow.Range.Cells(1, 6).Value = "" Then
            MsgBox "The Date, Service or Requesting Organisation has not been entered for every record in the table"
            Exit Sub
        End If
        
        'For every row, set value of combo to the name of the month that contains the date of the row
        Combo = tblrow.Range.Cells(1, 26).Value

        If tblrow.Range.Cells(1, 6).Value = "Ang Wes" Then
            DocYearName = tblrow.Range.Cells(1, 37).Value
        Else
            DocYearName = tblrow.Range.Cells(1, 36).Value
        End If

        'If Workbooks(ThisWorkbook.Path & "\" & DocYearName).Open = True Then
        'Workbooks(ThisWorkbook.Path & "\" & DocYearName).Close
        'Else
        'To open the workbook stored in the variable DocYearName
        
        Set wbDst = Workbooks.Open(ThisWorkbook.Path & "\" & DocYearName)

        Set wsDst = wbDst.Worksheets(Combo)
        
        lr = wsDst.Cells.Find("*", , xlValues, , xlRows, xlPrevious).Row
        
        With wsDst
            'This copies the first 10 columns, i.e. A:J, of the current row of the table to column A in the destination sheet.
            tblrow.Range.Resize(, 10).Copy
            'This pastes in the figures in the first 10 columns starting in column A
            .Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteFormulasAndNumberFormats
            'Overwrites the numbers pasted to column I with a formula
            .Range("I" & .Range("I" & .Rows.Count).End(xlUp).Row).Formula = "=IF(R[0]C[-4]=""*Activities"",0,RC[-1]*0.1)"
            'Overwrites the numbers pasted to column J with a formula
            .Range("J" & .Range("J" & .Rows.Count).End(xlUp).Row).Formula = "=IF(R[1]C[-5]=""*Activities"",RC[-2],RC[-1]+RC[-2])"
            'sort procedure copied from vba
            wsDst.Sort.SortFields.Clear
            wsDst.Sort.SortFields.Add Key:=Range("A4:A" & lr), _
                                      SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
            With wbDst.Worksheets(Combo).Sort
                .SetRange Range("A3:AK" & lr)
                .Header = xlYes
                .MatchCase = False
                .Orientation = xlTopToBottom
                .SortMethod = xlPinYin
                .Apply
            End With
            
        End With
        
        'save and close the workbook
        wbDst.Close SaveChanges:=True
        'End If

    Next tblrow

    With Application
        .CutCopyMode = False
        .ScreenUpdating = True
        .Calculation = xlCalculationAutomatic
        .DisplayAlerts = True
        .EnableEvents = True
    End With
    
End Sub
 
Upvote 0
I still get the same error, "method open of objects workbooks failed" with that code Norie with the following line of code highlighted:

Code:
Set wbDst = Workbooks.Open(ThisWorkbook.Path & "\" & DocYearName)
 
Upvote 0
What is the exact value of DocYearName?

Does it include the appropriate file extension e.g. xlsx, xlsm?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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