View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Tomu Tomu is offline
external usenet poster
 
Posts: 1
Default Workbooks.Open doesn't open file in ThisWorkbook

I'm attempting to open a 2nd workbook from a command button on the
1st. The 2nd file, in turn, is to open a companion file (File3.xls).
Problem is that "File2" won't open "File3". To test to see if this
code segment was even being executed on startup I placed a MsgBox in
it. The MsgBox always comes up.
However, if I open "File2" directly from Excel everything works OK.

To summarize the results in each case, the sequence is:
Case A: 1) From with Excel, Open File1; 2) Click CommandButton1,
which opens "File2"; 3) MsgBox comes up, but File3 never opens.
Case B: 1) From within Excel, Open File2; 2) MsgBox comes up AND
File3 opens.
What gives?

CODE IN FIRST FILE:
Private Sub CommandButton1_Click()
Workbooks.Open FileName:="C:File2.xls", updatelinks:=True
End Sub

CODE IN 2ND FILE (ThisWorkbook):
Private Sub Workbook_Open()
Workbooks.Open FileName:="C:File3.xls"
' I also tried the following command:
' Application.Workbooks.Open "C:\File3.xls"
prompt = "This works"
dummy = MsgBox(prompt, vbOKOnly, "Test")
End Sub