Start VBA upon opening

  • Thread starter Thread starter KENNY
  • Start date Start date
K

KENNY

Still struggling to get the code below to start when I (or
Windows Scheduler) open the workbook where it resides. As
a newbie, feel free to point out the obvious!

TIA


Public Sub CopySourceData()

Dim wbs As Workbooks
Dim wbdest As Workbook
Dim wsdest As Worksheet

Dim wbsource As Workbook
Dim wssource As Worksheet

Dim varFileList As Variant

Dim lngIndex As Long
Dim lngIndexMax As Long
lngIndex = 0
lngIndexMax = 300


ReDim varFileList(lngIndexMax)


strFileName = Dir("B:\International Target
Customer\2004 ITC Downloads\*.xls")

Do While Len(strFileName) > 0
lngIndex = lngIndex + 1
varFileList(lngIndex) = strFileName
If lngIndex > lngIndexMax Then

blah blah.............
 
Super easy to do :-)

In the VB Editor, in the Project - VBAProject window, right click on
"ThisWorkbook" and View Code. Paste this into it:

Private Sub Workbook_Open()
End Sub

That's it! When the workbook is opened this code is executed so simply put
your code into the subroutine.
 
Oops... Thanks for the responses. Here are my remaining
problems:

1. How do I edit this thing without running it upon
opening?

2. The code opens another workbook that contains a macro
that I want to enable, but automatically. What is the
syntax for that?

Thanks again!
 
Sorry about the other messages. I have two remaining
issues:

1. How do I edit this thing when opening it launches the
procedure?

2. This code opens another workbook with macros I want to
automatically enable. What is the syntax for that --
EnableMacros = True??

Thanks again.
 
#1: You don't want the code to run???
Turn security to High (disable macros) and then open your workbook.
or hold the ctrl key when opening your workbook. Macros will be enabled, but
the open routines won't run.

#2: You want to run the auto_open when you open the other workbooks?
if yes, then look at ActiveWorkbook.RunAutoMacros in help.

But if you really mean enabled, then if your code is running, the macros in the
other workbooks will be enabled. (trust the first, trust all the rest that the
first opens)
 
I think Dave meant that you need to hold down the shift key when opening the
workbook, at least that is what it is on my version, XP.

Sue
 
I'm not sure what I meant, but I should have meant shift!

Thanks for the correction.

Sue said:
I think Dave meant that you need to hold down the shift key when opening the
workbook, at least that is what it is on my version, XP.

Sue
<<snipped>>
 

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

Back
Top