Microsoft excel macros - Workbook names

Closed
Dan - Apr 3, 2011 at 10:54 AM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Apr 3, 2011 at 04:39 PM
Hello,

I am having a slight issue with a Macro within excel.

I have a template file, with a working macro which does X Y and Z, (Summary is that it copies lots of cells from a 2nd spreadsheet, pastes it into the template (or current open xls file) then close the 2nd spreadsheet).

The issue I have is that within the macro I use the following line:

Windows("QuoteTemplate.xls").Activate

which means that when I "SaveAs" and change the filename which contains the macro, I get an error because the macro tries to paste the files into the QuoteTemplate.xls, NOT the currently open (and renamed) xls file.

Is there a way to either change the above line to automatically replace it with the current filename [like Windows(this.worksheet).Activate] or when even maybe to change the line when I saveAs (so whatever I saveAs will replace the "QuoteTemplate.xls" with the name I use)

Any help would be much appreciated

Dan


Related:

1 response

rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Apr 3, 2011 at 04:39 PM
since the macro reside in the template that I guess you resave as save-as. In such case you can try
thisworkbook.activate
0