![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Apr 2002
Location: Alberta, Canada
Posts: 50
|
My macro refers to the excel file (05 may information systems) I am in as i open another excel file. I now want to use this macro in a new excel file (06 june information systems). is there anyway i can get around having to reenter the macro code and change the file name reference?
Workbooks.Open ("G:ComptrolMonthly ActualsMonthly Actuals1417.xls") Windows("Monthly Actuals1417.xls").Activate Cells.Select Selection.Copy Windows("05 May Information Systems rev1.xls").Activate |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Apr 2002
Posts: 85
|
Try this. This will prompt you to locate the file you want to open
sub ImportFile () Dim fileToOpen as string fileToOpen = Application.GetOpenFilename("Microsoft Excel Files (*.xls), *.xls") If fileToOpen <> False Then Workbooks.Open fileToOpen Range("A6").Select Else Exit Sub End If exit sub |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Apr 2002
Location: Alberta, Canada
Posts: 50
|
the external file name always stays the same. its the file that houses the macro that i am continually changing. i don't want to have to select the filename everytime i open the file (the macro auto runs at opening)
|
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Apr 2002
Posts: 85
|
try using a variable to hold the name:
dim Name as string Name = activeworkbook.name is that what you are talking about? |
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Apr 2002
Location: Alberta, Canada
Posts: 50
|
i think so. So i use that instead of typing in the name manually. Do all i have to do is copy that into my macro?
Edit: ok. i just replace 05 may information systems.xls with Name Thanks [ This Message was edited by: excelmacro on 2002-05-02 14:42 ] |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|