Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to auto start a vba script when my workbook opens

Status
Not open for further replies.

csmikle

IS-IT--Management
Jun 5, 2003
2
CA
Hi

I am new to VBA but someone did a script for me in excel that is activated by the click of a button, I have done some changes to the script and now want the script to run when I open the excel workbook. In the VBA project explorer this script is under Forms called UserForm1. My research indicates that I need to put my "macro" in a WorkBook_Open under ThisWorkbook.

How can I refer to Userform1 from ThisWorkbook?

 
you need to copy and paste the code into the This_Workbook module and put it in the Workbook_Open subroutine

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
How can I refer to Userform1 from ThisWorkbook?
Preface your Userform properties, methods or dependent controls (CommandButtons, ListBoxes, etc.) with Userform1. Example:
Code:
Userform1.Caption = "Data Input"


Regards,
Mike
 
Here is what I have presently

Private Sub Workbook_Open()
Application.Run ("Auto_Prd_Rep.xls!UserForm1")

End Sub

and here is the error it gives
Runtime error '1004'
The Macro 'Auto_Prod_rep.xls!UserForm1' cannot be found

where Auto_Prod_rep.xls is the name of the excel workbook
 
try:

UserForm1.Show

Hope this helps.

Ron

Ron Repp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top