![]() |
![]() |
|
|||||||
| 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: Mar 2002
Posts: 75
|
Here is my query. Is there a way to right in code that would tell excel to activate or select the workbook that the macro is located in.
example: I have a macro that opens another workbook and copies several cells from that workbook. Then I need to paste those copied cells into a the workbook that the macro was written in or associated with. I know I could do this buy using the file name of the destination sheet, but that changes regularly. but the same macro will always be associated with a given workbook no matter what the workbook name. If anyone out here has any idea if this is possible I would apreciate the help. |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Feb 2002
Location: Stockton, California
Posts: 281
|
Yes, in your macro, before you open any other workbooks, just set a variable.
Dim currentworkbook as string currentworkbook=activeworkbook.name put that in before you open any other workbooks, then later you can refer to the original workbook as "currentworkbook" |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Mar 2002
Posts: 75
|
Thanks very much, I have been look for that little tid bit for a while..
|
|
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
As an Alternative to RobFo0s help....
In your code Use the ThisWorkbook Object qualifyer to reference the workbook that the code is currently from. Eg instead of Workbook(whatever).dosomething use Thisworkbook.dosomething |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|