Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default 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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default 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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default 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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Refering a cell Arun Kumar Saha Excel Worksheet Functions 2 June 18th 07 12:48 PM
Refering to Cells madh83 Excel Worksheet Functions 3 July 19th 06 11:39 PM
logic stmt. use in a new workbook w/o refering back to original billybob Excel Worksheet Functions 1 August 4th 05 05:21 PM
Refering to Names VJ Excel Programming 2 April 21st 05 05:40 PM
Refering to Desktop Lynda Excel Programming 3 February 1st 05 01:57 AM


All times are GMT +1. The time now is 10:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"