method open of object workbooks failed

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,362
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 replaced the line of code and if stopped deleting lines altogether.

This is what I now have:
Code:
Private Sub cmdDelSelectRow_Click()

ActiveSheet.Unprotect Password:="npssadmin"
    Dim rng As Range
    
    On Error Resume Next
    With Selection.Cells(1)
        Set rng = Intersect(.EntireRow, ActiveCell.ListObject.DataBodyRange)
        On Error GoTo 0
        If rng Is Nothing Then
            MsgBox "Please select a cell within a row that you want to delete.", vbCritical
        Else
            If rng.HasFormula = False Then rng.Delete
        End If
    End With
    
'ListObjects("NPSS_quote").ListColumns("10%Increase").DataBodyRange.Value = "1"

Application.EnableEvents = True
'ActiveSheet.Protect Password:="npssadmin"
End Sub

Is there something I left out.
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Do the rows getting deleted contain formulas ??
If any cells on that rows hold a formula, the code won't remove that row !!
 
Last edited:
Upvote 0
Every row contains cells that have formulas at the end of the table. I wanted the selected rows to be deleted, but if there is only one row left in the table and the button is clicked on the delete selected row when the last row is selected, I want the contents deleted, which is in columns up to H and everything else left. All the rest are formulas.
 
Upvote 0
I think I am going to try and convert it all to use a range instead of tables. I am going to need some help on the code for all of the buttons. I don't know where to start. I have poured months of effort at work into this and doing so will mean that all of the work I have put in will be wasted. This will also make my supervisor very annoyed. I have no idea what to do Michael. :(
 
Upvote 0
Yeah, you're probably too far down the path now to really change !!
You could create a copy and start to convert it in your spare time.
In the meantime try

UNTESTED

Code:
Private Sub cmdDelSelectRow_Click()

ActiveSheet.Unprotect Password:="npssadmin"
    Dim rng As Range
    
    On Error Resume Next
    With Selection.Cells(1)
        Set rng = Intersect(.EntireRow, ActiveCell.ListObject.DataBodyRange)
        On Error GoTo 0
        If rng Is Nothing Then
            MsgBox "Please select a cell within a row that you want to delete.", vbCritical
        End If
        If rng.Offset(1).HasFormula = True Then
        rng.Delete
        Else
            Exit Sub
        End If
    End With
    
'ListObjects("NPSS_quote").ListColumns("10%Increase").DataBodyRange.Value = "1"

Application.EnableEvents = True
'ActiveSheet.Protect Password:="npssadmin"
End Sub
 
Upvote 0
That didn't work Michael, but I thought of an idea. What if there was some code to delete a row but if it is the last row left or row 5, insert the formulas back into the cells. The header row is row4 and the data starts in row 5. For every record in the table, the date is in column A and..


  • there is a formula in column Z
    • Code:
      =TEXT(DATE(YEAR(A5),IF(DAY(A5)<26,MONTH(A5),MONTH(A5)+1),1), "mmmm")
  • there is a formula in column AA
    • Code:
      =TEXT(DATE(YEAR(A5),IF(DAY(A5)<26,MONTH(A5),MONTH(A5)+1),1), "yyyy")
  • there is a formula in column AD
    • Code:
      =CONCATENATE(AA5+1," - ",AA5+2)
  • there is a formula in column AG
    • Code:
      =IF(MONTH(A5)<7,YEAR(A5)-1,YEAR(A5))
  • there is a formula in column AH
    • Code:
      =IF(MONTH(A5)<7,YEAR(A5),YEAR(A5)+1)
  • there is a formula in column AI
    • Code:
      =CONCATENATE(AG5," - ",AH5)
  • there is a formula in column AJ
    • Code:
      =CONCATENATE(AI5," ","NPSS Work Allocation Sheet.xlsm")
  • there is a formula in column AK
    • Code:
      =CONCATENATE(AI5," ","Internal Work Allocation Sheet.xlsm")


Thanks Michael,
Dave
 
Upvote 0
If I start again with multiple ranges instead of tables, can you give me some tips to give me a little head start on the coding please?
 
Upvote 0
Perhaps start a new topic for this new issue. :)
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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