Excel VBA basics

P

Philipp

Hello,
I wonder why the following Excel VBA code does not work.

Sub test()
Dim myBook As Workbook
myBook = ActiveWorkbook
Debug.Print "the book name is" & myBook.Name
End Sub

Is it not possible to assign the reference to the workbook to a variable?
Thanks for answers Phil
 
H

Haldun Alay

Hi,
Try


.......
Set myBook = ActiveWorkbook
........


Kind Regards.
--
Haldun Alay
"Philipp" <[email protected]>, haber iletisinde sunlari yazdi:[email protected]...
Hello,
I wonder why the following Excel VBA code does not work.

Sub test()
Dim myBook As Workbook
myBook = ActiveWorkbook
Debug.Print "the book name is" & myBook.Name
End Sub

Is it not possible to assign the reference to the workbook to a variable?
Thanks for answers Phil
 
A

Andy Pope

Hi,

You need to use the Set command as it is an object variable.

Set myBook = ActiveWorkbook

Cheers
Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top