ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Syntax to define a variable for current file (https://www.excelbanter.com/excel-programming/286037-syntax-define-variable-current-file.html)

Mervyn Thomas

Syntax to define a variable for current file
 
Can someone tell me how to define a variable to hold the name of the current
file so that later I can reactivate the file by referring to the variable
rather hard code its name?

Thanks - It escapes me !



Chip Pearson

Syntax to define a variable for current file
 
Mervyn,

Try something like

Dim FName As String
FName = ActiveWorkbook.Name
' more code here
Workbooks(FName).Activate


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Mervyn Thomas" wrote in message
...
Can someone tell me how to define a variable to hold the name

of the current
file so that later I can reactivate the file by referring to

the variable
rather hard code its name?

Thanks - It escapes me !





Dave Peterson[_3_]

Syntax to define a variable for current file
 
dim myWkbk as workbook
set mywkbk = activeworkbook
'''do lots of stuff
mywkbk.activate

But lots of times you don't even have to activate it to work with it.

mywkbk.worksheets("sheet1").range("B37").value = "Hi there"

would assign a text value to B37 in sheet1 of that workbook.

Mervyn Thomas wrote:

Can someone tell me how to define a variable to hold the name of the current
file so that later I can reactivate the file by referring to the variable
rather hard code its name?

Thanks - It escapes me !


--

Dave Peterson



All times are GMT +1. The time now is 01:27 PM.

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