Full Version: Open a second excel file when the first one opens?
UtterAccess Discussion Forums > Microsoft® Office > Microsoft Excel
Enigma007x
Heya-

I am using data from a second excel file in my main file. Is there a way I can open an excel file minimized in the background when the first one opens? And if so, can I then close it when the main one closes?

Thanks
Enigma
dannyseager
open the excel file, fress Alt + F11 to get into the VBA editor.

In the project pane double click on "this workbook"

Then change the first drop down menu from general to workbook and make sure the second one says open

add the following code

CODE
  Workbooks.Open Filename:="C:\filename.xls"


add the folowing code to the before close event for the workbook

CODE
Application.ScreenUpdating = False
    Windows("filename").Activate
    ActiveWindow.Close
    Application.ScreenUpdating = True


The close routine is probably the long way round but it works
Enigma007x
Great thanks!
Enigma007x
Hmmm. I seem to just be able to pull up "Worksheet" and "General". Worksheet doesn't have an "Open" event and I can't seem to access the workbook.

ANy thoughts?
Enigma007x
I'm an idiot. Found it in the Project Explorer as you had directed me tongue.gif Thanks Again!
Enigma007x
Okay... Yes, I need to lay off the coffee... tongue.gif I put the Workbooks.Open code in the open event of the workbook, but nothing appears to be running in terms of VBA. :( I tried just throwing a Msgbox "Hi" in with no results as well.

I have done quite a bit with Access, but I just started working with Excel. Do I have to enable the VB somehow?

Again, I appreciate everything!
Enigma
Luceze
Go to tools/Macro/Security and set it to medium. If it is set to High the code will not run. If it is set to Low then anything will run.

HTH,
Eric
dannyseager
did what "Jay & Silent Bob" Suggest work? frown.gif

if not let me know
Enigma007x
Sorry for the delay in response.

It worked like a charm. Thank you both! tongue.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.