Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Absolute Worksheet References

Hi there,

I read that (O'Reilly Excel Hacks, page 192) if you use "absolute"
Worksheet references that if the actual worksheet name changes that the
application will continue to work. This is true but I am using Excel
2003 and keep getting a reference not valid message, although the macro
still appears to work. Is there any way to fix this so that the
message does not appear?

To make myself clear:

Normally to reference a worksheet you can use:

1)
dim wks as Excel.Worksheet
set wks = ThisWorkbook.Worksheets("Sheet1")

OR

2)
dim wks as Excel.Worksheet
set wks = ThisWorkbook.Worksheets(1)

However, if you change Sheet1 to another name, (1) above breaks. If
you change the worksheet position within the workbook, (2) above
breaks.

However you are supposedly able to just reference a sheet by the name
given to it in the properties window. So looking in your Project
Explorer under Microsoft Excel Objects if you use the Codename of the
worksheet rather than the name you have given it (i.e. Sheet1, etc.)
you can reference the sheet directly without going through the above,
wiht the added benefit of it being (supposedly) impervious to worksheet
name changes... Except that it gives you this annoying Reference not
valid message.

Any help on getting the message to go away?

Regards,

Ric

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default Absolute Worksheet References

You are absolutely correct that it is better to reference teh code andm than
the tab name for the reasons you describe. I am not too sure what problem you
are having with Sheet1 as a valid reference (just as an aside in the
properties you can change the code name to something more descriptive like
shtRawData.

Try this

sub Test
msgbox Sheet1.Name
end sub

Note that the intellisence will work when you type the period which is
another advantage...
--
HTH...

Jim Thomlinson


"ric_deez" wrote:

Hi there,

I read that (O'Reilly Excel Hacks, page 192) if you use "absolute"
Worksheet references that if the actual worksheet name changes that the
application will continue to work. This is true but I am using Excel
2003 and keep getting a reference not valid message, although the macro
still appears to work. Is there any way to fix this so that the
message does not appear?

To make myself clear:

Normally to reference a worksheet you can use:

1)
dim wks as Excel.Worksheet
set wks = ThisWorkbook.Worksheets("Sheet1")

OR

2)
dim wks as Excel.Worksheet
set wks = ThisWorkbook.Worksheets(1)

However, if you change Sheet1 to another name, (1) above breaks. If
you change the worksheet position within the workbook, (2) above
breaks.

However you are supposedly able to just reference a sheet by the name
given to it in the properties window. So looking in your Project
Explorer under Microsoft Excel Objects if you use the Codename of the
worksheet rather than the name you have given it (i.e. Sheet1, etc.)
you can reference the sheet directly without going through the above,
wiht the added benefit of it being (supposedly) impervious to worksheet
name changes... Except that it gives you this annoying Reference not
valid message.

Any help on getting the message to go away?

Regards,

Ric


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Absolute Worksheet References

Hi Jim,

I can reference both the .Name and the .Codename properties from the
immediate window and the macros run as intended, it is just that prior
to the macros even executing I get an annoying Message Box with the
"Reference Not Valid" message. Are you using Excel 2003?

Regards,

Ric

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default Absolute Worksheet References

I have 2003. I don't have access to it right now but I do use it. I don't
think this is a matter of the version. In the VBE select Debug - Compile
VBA_Project. Does it compile?
--
HTH...

Jim Thomlinson


"ric_deez" wrote:

Hi Jim,

I can reference both the .Name and the .Codename properties from the
immediate window and the macros run as intended, it is just that prior
to the macros even executing I get an annoying Message Box with the
"Reference Not Valid" message. Are you using Excel 2003?

Regards,

Ric


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Absolute Worksheet References

Check under tools|references for that error message (I don't recall ever seeing
this, so it's a guess.)

But this worked ok for me (xl2003):

Option Explicit
Sub testme()
Dim wks As Worksheet
Set wks = Sheet2
Debug.Print wks.Name & "--" & wks.CodeName
End Sub

And I saw this in the immediate window.

ThisIsATest--Sheet2

ric_deez wrote:

Hi Jim,

I can reference both the .Name and the .Codename properties from the
immediate window and the macros run as intended, it is just that prior
to the macros even executing I get an annoying Message Box with the
"Reference Not Valid" message. Are you using Excel 2003?

Regards,

Ric


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Absolute Worksheet References

ric_deez wrote:

Normally to reference a worksheet you can use:

1)
dim wks as Excel.Worksheet
set wks = ThisWorkbook.Worksheets("Sheet1")

OR

2)
dim wks as Excel.Worksheet
set wks = ThisWorkbook.Worksheets(1)




Or

dim wks as Excel.Worksheet
set wks = ThisWorkbook.Sheet1


if Sheet1 is still a name of your worksheet set in property windows


Is this what you wanted to have?
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Absolute Worksheet References

dim wks as Excel.Worksheet
set wks = ThisWorkbook.Sheet1


That fails for me in Excel 2K, as does
set wks = ActiveWorkbook.Sheet1

but I can do -

Set wks = Sheet1

If I want to reference a worksheet with the codename "Sheet1" in any
workbook

For each wks in Activeworkbook
If wks.Codename = "Sheet1" then
msgbox wks.Name
' got my sheet, etc
End if
Next

Regards,
Peter T



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
convert relative cell references to absolute cell references via amacro? Dave F[_2_] Excel Discussion (Misc queries) 1 May 15th 08 04:43 PM
Help with converting a block of cells with Absolute and mixed references to relative references Vulcan Excel Worksheet Functions 3 December 13th 07 11:43 PM
Absolute References Dan Beard Excel Discussion (Misc queries) 3 October 16th 07 03:20 AM
Absolute References [email protected] Excel Worksheet Functions 1 November 29th 06 12:41 AM
Absolute references BWGames Excel Programming 1 December 31st 03 10:52 AM


All times are GMT +1. The time now is 09:53 PM.

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

About Us

"It's about Microsoft Excel"