Auto-Open other file

A

aposatsk

Upon opening my main excel file, I would like another file in the sam
folder to be opened. Is this possible
 
D

Dave Peterson

One way is to use a macro:

Option Explicit
Sub auto_open()
Dim WkbkName As String
Dim TestStr As String

WkbkName = "book2.xls"

TestStr = ""
On Error Resume Next
TestStr = Dir(ThisWorkbook.Path & "\" & WkbkName)
On Error GoTo 0

If TestStr = "" Then
MsgBox "design error! " & WkbkName & " wasn't found."
Else
Workbooks.Open Filename:=ThisWorkbook.Path & "\" & WkbkName
End If

End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
 
G

Gord Dibben

Another way is to save the files as a Workspace.

With both books open, File>Save Workspace.

A resume.xlw file will be created.

You can name it whatever you wish as long as you retain the XLW format.

Open that and both books will open.


Gord Dibben MS Excel MVP
 
A

aposatsk

Gord said:
Another way is to save the files as a Workspace.

With both books open, File>Save Workspace.

A resume.xlw file will be created.

You can name it whatever you wish as long as you retain the XL
format.

Open that and both books will open.


Gord Dibben MS Excel MVP

If i use this method, the files which open afterwards are the sam
files, except all "Splits" and "Frozen Panes" are gone, and some of th
sheets are zoomed to different levels than in the original. Is there an
way to fix this and retain the same format?

Also, if i edit File 1 and File 2 and save each afterwards, will m
Workspace file take into account these changes? or do i have to re-sav
the workspace
 
G

Gord Dibben

First problem..................have not been able to find a way to retain the
Splits and Frozen Panes.

Second problem.............yes, the workbooks are saved with changes if saved
individually or saved as workspace.


Gord
 
B

BigBen

aposatsk said:
Upon opening my main excel file, I would like another file in the same
folder to be opened. Is this possible?

You can try this by saving the files in a workspace, but then your viewing
settings (show gridlines, row/col headers, etc.) are all replaced by defaults.

The way that worked best for me was to enter code similar to the following
in the "ThisWorkbook" module of my primary workbook in Visual Basic:

Private Sub Workbook_Open()

Dim MyPath As String
MyPath = ThisWorkbook.Path

Workbooks.Open (MyPath & "\workbook4.xls") 'Alternatively, you could
specify the full path
Workbooks.Open (MyPath & "\workbook3.xls")
Workbooks.Open (MyPath & "\workbook2.xls")

Workbooks(1).Activate 'Places
primary workbook on top

Application.ShowWindowsInTaskbar = False 'These two lines might not
be needed on
Application.ShowWindowsInTaskbar = True 'your system

End Sub

Now, whenever my primary workbook is opened, the other workbooks open
automatically, looking just as they were when I last saved them. This
example requires all the workbooks involved to be in the same directory as
the primary one, but you could always specify full paths.

On my system, something weird happens with the taskbar if I omit the last
two lines of the procedure; you may or may not need them on your system.

Good luck!
 
Top