Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 166
Default xls name reference


I'm using the following function:

Function ReadCell(msheet, mCell)
'ReadCell = ActiveWorkbook.Worksheets(msheet).Range(mCell).Val ue
ReadCell = Workbooks("this.xls").Worksheets(msheet).Range(mCe ll).Value
End Function

The remmed out line caused a problem when two instances of Excel were
open at the same time, and the replacement line referencing the
absolute xls filename fixed this.

However, if the filename isn't "this.xls" it fails. Excel knows the
filename somehow, as it's used as the main Caption. Can I get at this
somehow and use it instead?

Thanks - Kirk


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default xls name reference

You can use ThisWorkbook for the workbook containing the code.

"kirkm" wrote:


I'm using the following function:

Function ReadCell(msheet, mCell)
'ReadCell = ActiveWorkbook.Worksheets(msheet).Range(mCell).Val ue
ReadCell = Workbooks("this.xls").Worksheets(msheet).Range(mCe ll).Value
End Function

The remmed out line caused a problem when two instances of Excel were
open at the same time, and the replacement line referencing the
absolute xls filename fixed this.

However, if the filename isn't "this.xls" it fails. Excel knows the
filename somehow, as it's used as the main Caption. Can I get at this
somehow and use it instead?

Thanks - Kirk



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default xls name reference

Hi Kirk,

You could use the following formula (Extracted from Help in xl2007) in a
cell in the workbook and then use the cell reference as the parameter.
However, I am interested if anyone has a better way of doing it.

=MID(CELL("filename"),SEARCH("[",CELL("filename"))+1,
SEARCH("]",CELL("filename"))-SEARCH("[",CELL("filename"))-1)

--
Regards,

OssieMac


"kirkm" wrote:


I'm using the following function:

Function ReadCell(msheet, mCell)
'ReadCell = ActiveWorkbook.Worksheets(msheet).Range(mCell).Val ue
ReadCell = Workbooks("this.xls").Worksheets(msheet).Range(mCe ll).Value
End Function

The remmed out line caused a problem when two instances of Excel were
open at the same time, and the replacement line referencing the
absolute xls filename fixed this.

However, if the filename isn't "this.xls" it fails. Excel knows the
filename somehow, as it's used as the main Caption. Can I get at this
somehow and use it instead?

Thanks - Kirk



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default xls name reference


kirkm;259330 Wrote:
I'm using the following function:

Function ReadCell(msheet, mCell)
'ReadCell = ActiveWorkbook.Worksheets(msheet).Range(mCell).Val ue
ReadCell = Workbooks("this.xls").Worksheets(msheet).Range(mCe ll).Value
End Function

The remmed out line caused a problem when two instances of Excel were
open at the same time, and the replacement line referencing the
absolute xls filename fixed this.

However, if the filename isn't "this.xls" it fails. Excel knows the
filename somehow, as it's used as the main Caption. Can I get at this
somehow and use it instead?

Thanks - Kirk


Hello Kirk,

If I understand your problem, you want to be able to reference the
workbook the code is in whenever you have 2 or more workbooks open at
the same time. Prefix any code that you want to refer to your workbook
(the one with the code in it) with ThisWorkbook. Otherwise VBA assumes
you are referring to whichever workbook is active.

---------------------------------------------
Function ReadCell(msheet, mCell)
ReadCell = ThisWorkbook.Worksheets(msheet).Range(mCell).Value
End Function
---------------------------------------------


--
Leith Ross

Sincerely,
Leith Ross

'The Code Cage' (http://www.thecodecage.com/)
------------------------------------------------------------------------
Leith Ross's Profile: http://www.thecodecage.com/forumz/member.php?userid=75
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=72419

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 166
Default xls name reference


Thank you all very much !

It's working perfectly, you guys are great ! :)

Cheers - Kirk
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
Changing sheet reference to cell reference TeeJay Excel Worksheet Functions 3 October 19th 07 11:50 AM
Column letter reference as number reference mcphc Excel Programming 8 January 30th 07 03:06 PM
Using an offset formula for the reference in a relative reference Cuda Excel Worksheet Functions 6 November 15th 06 05:12 PM
Formulas that reference cells that reference another cell Andrea Excel Discussion (Misc queries) 7 October 19th 06 08:14 AM
Macro to Reference Column Next to Current Reference dolphinv4 Excel Discussion (Misc queries) 2 April 11th 05 08:36 AM


All times are GMT +1. The time now is 12:31 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"