PDA

View Full Version : [SOLVED] Change a worksheet's code name to Sheet1



mikeburg
08-03-2015, 01:15 PM
I need help with VBA code that will change a worksheet's code name to Sheet1. I have tried several VBA examples from my search, but I can't get any to work.

In other words:

Rename: Sheet3(LgvLawnMonthly)
(the worksheets code name is not always Sheet 3, it could be Sheet8, etc.)

To: Sheet1(LgvLawnMonthly)

I am using MsOffice XP (2002).
I really appreciate any & all help.

mikeburg

p45cal
08-03-2015, 01:52 PM
ThisWorkbook.VBProject.VBComponents(Sheets("LgvLawnMonthly").CodeName).Name = "Sheet1"

mikeburg
08-03-2015, 03:49 PM
Thank you for your help.

When I copied the above vba & ran it, I get the following message:

Run-time error '1004'
Programmatic access to Visual Basic project is not trusted

Any ideas? Thanks so very much. mikeburg

p45cal
08-03-2015, 04:08 PM
See http://stackoverflow.com/questions/25638344/programmatic-access-to-visual-basic-project-is-not-trusted-excel there may be a button you have to click between 3 and 4 above:Trust Center Settings…
or
click 'Developer' > 'Macro Security' > 'Macro Settings' then check the "Trust access to the VBA Project object model". Then click 'OK'.

mikeburg
08-04-2015, 11:54 AM
Thank you so much! This works great! mikeburg

Kenneth Hobs
08-04-2015, 12:22 PM
I would recommend reading this for the pitfalls that can happen. http://www.spreadsheet1.com/vba-codenames.html

mikeburg
08-05-2015, 09:27 AM
Thank you so much! This helps. mikeburg