Assigning a variable to the activeworkbook

bearcub

Well-known Member
Joined
May 18, 2005
Messages
711
Office Version
  1. 365
  2. 2013
  3. 2010
  4. 2007
Platform
  1. Windows
I'm just trying to figure out what is happening with the following code (which is useless). I'm getting an error message in the last line of code saying that the object property is not supported by the wk object (or something to this effect):

Sub Module()
Dim wk As Workbook
Set wk = ThisWorkbook
wk.ActiveSheet.value= "5"
End Sub

What I'm trying to do is open a workbook and then copy the sheet names in that file into the activeworkbook. Instead of using the actual file name in the code I'm using the variable wk to be the active workbook. I then add a line to open another file and make a copy list of all the sheets that are that file then paste them into the wk file on the active sheet. I was able to figure out how to do this but during the process I noticed that when I set the activeworkbook to "wk" I couldn't do something like this "wk.Activesheet.activecell.value = "5".

It seems that the intelliisense dropdown doesn't pop up after the activesheet object is added to the wk variable. All I can get to work for the activesheet object is "wk.activesheet". The above code definitely gives an error message when it gets to the last line because for some reason VBA doesn't recognize the .value property (it doesn't show up as a property in the activesheet object). Why is that? I noticed that a number of the workbook and worksheet properties/methods disappear I use the set statement. Why is that?

Michael
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Just checking to see if this went through
 
Upvote 0

Forum statistics

Threads
1,215,558
Messages
6,125,511
Members
449,236
Latest member
Afua

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