ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   use current file and folder name (https://www.excelbanter.com/excel-discussion-misc-queries/170317-use-current-file-folder-name.html)

mohavv

use current file and folder name
 
Is it possible to use the value of the file and folder name in a
macro?

For example, when you rename/copy a file you want the following code
to change:

Windows("2007 Accounts.xls").Activate

If you copy the file containing the macro it will want to activate the
old file and it should activate the new file.

Cheers,

Harold

Dave Peterson

use current file and folder name
 
If your code is in a general module, you can use ThisWorkbook, like:

Thisworkbook.windows(1).activate

Or

Thisworkbook.worksheets("somesheetnamehere").range ("a1").clearcontents

If your code is behind the ThisWorkbook module, you can use the Me keyword.

me.windows(1).activate
me.worksheets("somesheetnamehere").range("a1").cle arcontents
(me refers to the object that owns the code.)

===
(Actually, you can use ThisWorkbook in any module to refer to the workbook that
owns the code.)

mohavv wrote:

Is it possible to use the value of the file and folder name in a
macro?

For example, when you rename/copy a file you want the following code
to change:

Windows("2007 Accounts.xls").Activate

If you copy the file containing the macro it will want to activate the
old file and it should activate the new file.

Cheers,

Harold


--

Dave Peterson


All times are GMT +1. The time now is 05:28 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com