I'm Writing a VBA macro in excel that is supposed to open "fileB.xls" and then close immediately after it opens. Since we will be talking about 3 excel files I'll call the first one fileA.
The code for the buttons on the userform for file A look like the following.
Private Sub CommandButton2_Click()
'Code for Button in FileA '
Workbooks.Open Filename:="File Path/fileB.xls"
ThisWorkbook.Close
End Sub
Once "fileB.xls" opens it launches a form to collect some user information.
However the original file does not close after, "fileB.xls" is opened.
Sub Workbook_Open()
'Code in FileB '
'Display a form to obtain information from the user. '
frmOpenFile.Show
End Sub
It might be worth noting that fileB opens a third and final excel file (FileC). Code that is similar to FileA's code is used in FileB and work fine when launching FileC (FileB closes fine).
The idea is that there is one "master" file where you choose which form you need to fill out. This master file then closes itself and lets the user fill out the form, and based upon user input a final excel file is opened.
So, just to reiterate the problem, FileA opens, launches a userform, the user clicks on a button, File B lauches, FileA does not close when it should.
I would be grateful for any help!
EDIT: I should note that if rewrite FileA to directly open FileC, FileA closes correctly. Could the user form from FileB prevent File A from closing?