Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Refering a cell | Excel Worksheet Functions | |||
Refering to Cells | Excel Worksheet Functions | |||
logic stmt. use in a new workbook w/o refering back to original | Excel Worksheet Functions | |||
Refering to Names | Excel Programming | |||
Refering to Desktop | Excel Programming |