My VBA sensei has left for pastures new and on the 1st day I am having a problem "Unable to set the Close property of the workbook class"

RockandGrohl

Well-known Member
Joined
Aug 1, 2018
Messages
801
Office Version
  1. 365
Platform
  1. Windows
Have the below code to simply create a new tab, then open a new workbook, switch between the two tabs and then close the workbook.

Code:
' Add Price Panel information to Temp sheet.

Sheets.Add.Name = "Temp"
Set Temp = Worksheets("Temp")


Temp.Activate
Range("A1").Activate


Set PP = Workbooks.Open("H:\Sales\Price Panels\Price Panels 2019.xlsm", ReadOnly:=True)


    Dim Lastrow As Long


    Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
    
    Range("A3").Activate
    Range("A2:B" & Lastrow).Copy
    Temp.Activate
    Range("A1").PasteSpecial xlPasteValues
    PP.Activate
    Range("D2:D" & Lastrow).Copy
    Temp.Activate
    Range("C1").PasteSpecial xlPasteValues
    PP.Activate
    Range("G2:G" & Lastrow).Copy
    Temp.Activate
    Range("D1").PasteSpecial xlPasteValues
    PP.Activate
    Range("M2:M" & Lastrow).Copy
    Temp.Activate
    Range("E1").PasteSpecial xlPasteValues


PP.Close = False

Here's what's weird - when I step through the code with F8, it all goes well until "Set PP = Workbooks.Open" blah blah blah, from there, it seems to just run through the entire code up till the end - PP.Close = False, which is where I get the error

"Unable to set the Close property of the workbook class"

From googling this, I can't see anyone with the same issue, which is really strange.


The code is more or less lifted from other workbooks which happily work.

The copy+paste functionality seems to work very well, I can see it has the correct values included.
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Code resuming after workbook.open is just one of those (annoying) things. You will need to add a stop on the very next line to continue stepping through.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

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