![]() |
refering to a workbook name within vba
I have a workbook named say "expenses" and i have macros built in. I want to refer to that workbook name within the code but i dont know how. I am in effect switching between two different workbooks. I know how to refer to a cell reference within the workbook but i dont know if the workbook named is 'stored' anywhere in order to refer to. Hope this makes sense ? Thanks Darren -- DarrenWood ------------------------------------------------------------------------ DarrenWood's Profile: http://www.excelforum.com/member.php...o&userid=16460 View this thread: http://www.excelforum.com/showthread...hreadid=384009 |
refering to a workbook name within vba
Darren, I think you want something like this:
Workbook("Expenses").Activate Mike F "DarrenWood" wrote in message ... I have a workbook named say "expenses" and i have macros built in. I want to refer to that workbook name within the code but i dont know how. I am in effect switching between two different workbooks. I know how to refer to a cell reference within the workbook but i dont know if the workbook named is 'stored' anywhere in order to refer to. Hope this makes sense ? Thanks Darren -- DarrenWood ------------------------------------------------------------------------ DarrenWood's Profile: http://www.excelforum.com/member.php...o&userid=16460 View this thread: http://www.excelforum.com/showthread...hreadid=384009 |
refering to a workbook name within vba
It's usually safer to include the extension in that name:
workbooks("expenses.xls").activate Mike Fogleman wrote: Darren, I think you want something like this: Workbook("Expenses").Activate Mike F "DarrenWood" wrote in message ... I have a workbook named say "expenses" and i have macros built in. I want to refer to that workbook name within the code but i dont know how. I am in effect switching between two different workbooks. I know how to refer to a cell reference within the workbook but i dont know if the workbook named is 'stored' anywhere in order to refer to. Hope this makes sense ? Thanks Darren -- DarrenWood ------------------------------------------------------------------------ DarrenWood's Profile: http://www.excelforum.com/member.php...o&userid=16460 View this thread: http://www.excelforum.com/showthread...hreadid=384009 -- Dave Peterson |
refering to a workbook name within vba
Darren,
To refer to the name of the workbook the macro is in use ThisWorkbook.Name, e.g., MsgBox ThisWorkbook.Name hth, Doug "DarrenWood" wrote in message ... I have a workbook named say "expenses" and i have macros built in. I want to refer to that workbook name within the code but i dont know how. I am in effect switching between two different workbooks. I know how to refer to a cell reference within the workbook but i dont know if the workbook named is 'stored' anywhere in order to refer to. Hope this makes sense ? Thanks Darren -- DarrenWood ------------------------------------------------------------------------ DarrenWood's Profile: http://www.excelforum.com/member.php...o&userid=16460 View this thread: http://www.excelforum.com/showthread...hreadid=384009 |
refering to a workbook name within vba
I'd use a variable.
dim ExpWkbk as workbook 'if I had to open it: set expwkbk = workbooks.open(filename:="c:\somepath\expenses.xls ") Then I'd use that variable when I wanted to refer to that workbook. expwkbk.worksheets(1).range("a1").value = "hi there!" The nice thing about that is that I only have to update the code once when (not if!) the workbook changes name. And if I wanted, I could let the user choose his workbook to open. Dim fName As Variant dim ExpWkbk as workbook fName = Application.GetOpenFilename(filefilter:="Excel Files, *.xls") If fName = False Then Exit Sub 'user hit cancel End If set expwkbk = workbooks.open(filename:=fName) DarrenWood wrote: I have a workbook named say "expenses" and i have macros built in. I want to refer to that workbook name within the code but i dont know how. I am in effect switching between two different workbooks. I know how to refer to a cell reference within the workbook but i dont know if the workbook named is 'stored' anywhere in order to refer to. Hope this makes sense ? Thanks Darren -- DarrenWood ------------------------------------------------------------------------ DarrenWood's Profile: http://www.excelforum.com/member.php...o&userid=16460 View this thread: http://www.excelforum.com/showthread...hreadid=384009 -- Dave Peterson |
All times are GMT +1. The time now is 05:35 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com