PC Review


Reply
Thread Tools Rate Thread

Changing Codename in VBA

 
 
Dennis
Guest
Posts: n/a
 
      17th Nov 2006
2003


If I run this code is the respective w/s ThisWorkbook code window it
works fine.

ThisWorkbook.VBProject.VBComponents(wks.CodeName).Name = "Sheet2"

But if I run the code from another module I get an error 9 Subscript
not found or out of range. I did activate the worksheet in VBA prior
to running the code.

That said, I would like to change a Copied w/s Codename because it kept
the same Codename in the previous file. I would like to change the
Codename to "Sheet2" with VBA from another module.
Is this possible?

TIA EagleOne

 
Reply With Quote
 
 
 
 
Chip Pearson
Guest
Posts: n/a
 
      17th Nov 2006
Your code works fine for me as long as it is called from any module within
the same VBProject. If you call it from Workbook2 and Wks refers to a
worksheet in Workbook1, the code will fail.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)

"Dennis" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 2003
>
>
> If I run this code is the respective w/s ThisWorkbook code window it
> works fine.
>
> ThisWorkbook.VBProject.VBComponents(wks.CodeName).Name = "Sheet2"
>
> But if I run the code from another module I get an error 9 Subscript
> not found or out of range. I did activate the worksheet in VBA prior
> to running the code.
>
> That said, I would like to change a Copied w/s Codename because it kept
> the same Codename in the previous file. I would like to change the
> Codename to "Sheet2" with VBA from another module.
> Is this possible?
>
> TIA EagleOne
>



 
Reply With Quote
 
Dennis
Guest
Posts: n/a
 
      17th Nov 2006

Actually, I am calling from my Personal.xls but your point is still
valid.
I am still trying to conceive a workaround.

Thanks Chip.

Chip Pearson wrote:
> Your code works fine for me as long as it is called from any module within
> the same VBProject. If you call it from Workbook2 and Wks refers to a
> worksheet in Workbook1, the code will fail.
>
>
> --
> Cordially,
> Chip Pearson
> Microsoft MVP - Excel
> Pearson Software Consulting, LLC
> www.cpearson.com
> (email address is on the web site)
>
> "Dennis" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 2003
> >
> >
> > If I run this code is the respective w/s ThisWorkbook code window it
> > works fine.
> >
> > ThisWorkbook.VBProject.VBComponents(wks.CodeName).Name = "Sheet2"
> >
> > But if I run the code from another module I get an error 9 Subscript
> > not found or out of range. I did activate the worksheet in VBA prior
> > to running the code.
> >
> > That said, I would like to change a Copied w/s Codename because it kept
> > the same Codename in the previous file. I would like to change the
> > Codename to "Sheet2" with VBA from another module.
> > Is this possible?
> >
> > TIA EagleOne
> >


 
Reply With Quote
 
Dennis
Guest
Posts: n/a
 
      17th Nov 2006

Actually, I am calling from my Personal.xls but your point is still
valid.
I am still trying to conceive a workaround.

Thanks Chip.

Chip Pearson wrote:
> Your code works fine for me as long as it is called from any module within
> the same VBProject. If you call it from Workbook2 and Wks refers to a
> worksheet in Workbook1, the code will fail.
>
>
> --
> Cordially,
> Chip Pearson
> Microsoft MVP - Excel
> Pearson Software Consulting, LLC
> www.cpearson.com
> (email address is on the web site)
>
> "Dennis" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 2003
> >
> >
> > If I run this code is the respective w/s ThisWorkbook code window it
> > works fine.
> >
> > ThisWorkbook.VBProject.VBComponents(wks.CodeName).Name = "Sheet2"
> >
> > But if I run the code from another module I get an error 9 Subscript
> > not found or out of range. I did activate the worksheet in VBA prior
> > to running the code.
> >
> > That said, I would like to change a Copied w/s Codename because it kept
> > the same Codename in the previous file. I would like to change the
> > Codename to "Sheet2" with VBA from another module.
> > Is this possible?
> >
> > TIA EagleOne
> >


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Codename not set BigJimmer Microsoft Excel Programming 3 27th Feb 2010 04:49 AM
Codename not set BigJimmer Microsoft Excel Programming 2 6th Oct 2009 06:19 PM
Changing sheet content using codename =?Utf-8?B?TWFrZUxlaQ==?= Microsoft Excel Programming 2 7th Sep 2006 08:51 AM
codename help Gary Keramidas Microsoft Excel Programming 14 31st Oct 2005 12:32 AM
Worksheet codename Andy Microsoft Excel Programming 6 2nd Dec 2003 04:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:15 PM.