Automatically open VBA editor?

  • Thread starter Thread starter GB
  • Start date Start date
G

GB

I am just messing around, trying to get to grips with VBA. Some of it seems
quite simple, other bits annoyingly frustrating.

I have a couple of spreadsheets I am working on just to teach myself VBA. On
a whim, really, I thought it would be helpful to get the spreadsheets to
fire up the VBA editor and go to the code modules as soons as it is opened.

Just to take things one at a time, I stuck the following code into a
Workbook module

Private Sub Workbook_Open()
MsgBox "Hello"
End Sub

Now, I kind of expected that this would immediately say hello to me when I
open the workbook - but it does not do so. Can someone explain why not?
Please! What am I doing wrong?

If I can get that to work, I was going to replace the MsgBox command (am I
allowed to say command any longer?) with
Sendkeys "%(F11)(F7)"
Should that work?

Thanks

Geoff
 
GB,

Your code looks fine to me, did you put it in the correct place?
It has to be in the "ThisWorkbook" Code window.

Dan E
 
Hi Geoff,
The code should be in the module "ThisWorkbook" and you need to use braces
to send keycodes, as opposed to string or numeric data.
See the keycode list in help.

Private Sub Workbook_Open()
MsgBox "Hello"
SendKeys "%{F11}"
SendKeys "{F7}"
End Sub
 
Thanks, Dan and John. That was really helpful of you. Once I calmed down a
bit (after posting here) I gave it another go and worked it out, but thanks
very much anyway.

Geoff
 
You may also want to check the "Microsoft Visual Basic for Applications
Extensibility" library, VBE6EXT.OLB, which can give you some functionality
to control the VBE. (Not essential, but possibly useful.)
--
HTH -

-Frank
Microsoft Excel MVP
Dolphin Technology Corp.
http://vbapro.com
 
Back
Top