G
Guest
Hi! I have troubles with the Workbooks.Open method.
I want to open a file (power_budget.xls) from a main workbook with a userform menu (main.xls). I used Workbook.Open("power_budget.xls") method to open it and it works well, but now the problem arises.
power_budget.xls should ask the user for the path of an excel file containing data to be imported. I stored the sub to show the form that asks for the path in ThisWorkbook with an event sub like this one:
Private Sub Workbook_Open()
userform.show
End sub
When the CommandButton I put in the userform is clicked, another event Sub should open the data file with a call like this:
Set source = Workbook.Open("datafile.xls")
then read the data and import them in power_budget.xls, but that doens't happen!
When I ran the debugger I noticed that the source doesn't contain "datafile.xls" but "power_budget.xls" again, and I can't understand why this happens and how to fix it. I know the code stored in power_budget.xls is correct, because when I open it directly (without using main.xls), everything works in the right way.
Can anyone help with this problem?
10x everybody
Amarth
I want to open a file (power_budget.xls) from a main workbook with a userform menu (main.xls). I used Workbook.Open("power_budget.xls") method to open it and it works well, but now the problem arises.
power_budget.xls should ask the user for the path of an excel file containing data to be imported. I stored the sub to show the form that asks for the path in ThisWorkbook with an event sub like this one:
Private Sub Workbook_Open()
userform.show
End sub
When the CommandButton I put in the userform is clicked, another event Sub should open the data file with a call like this:
Set source = Workbook.Open("datafile.xls")
then read the data and import them in power_budget.xls, but that doens't happen!
When I ran the debugger I noticed that the source doesn't contain "datafile.xls" but "power_budget.xls" again, and I can't understand why this happens and how to fix it. I know the code stored in power_budget.xls is correct, because when I open it directly (without using main.xls), everything works in the right way.
Can anyone help with this problem?
10x everybody
Amarth