I am trying to copy an Excel worksheet from one workbook into another through Access VBA. I have the file name set in a variable called txtReportFile.
I am getting a "type mismatch error" in the following line:
It works fine when I type the name of the file in quotes instead of using the variable, but I will not know the name of the file until the program is run, hence the variable. I believe it has something to do with the fact that txtReportFile contains a path AND a file (i.e. "C:\data\file.xls") instead of just "file.xls" but I don't know how to get just the file name. Any ideas how I can get this to work?
Kelly
I am getting a "type mismatch error" in the following line:
Code:
Sheets("Key-Factors").Copy Before:=Workbooks(txtReportFile).Sheets(1)
It works fine when I type the name of the file in quotes instead of using the variable, but I will not know the name of the file until the program is run, hence the variable. I believe it has something to do with the fact that txtReportFile contains a path AND a file (i.e. "C:\data\file.xls") instead of just "file.xls" but I don't know how to get just the file name. Any ideas how I can get this to work?
Kelly