Hopefully an easy one...

klarowe

Active Member
Joined
Mar 28, 2011
Messages
389
Is there a way to change the order of the sheets in the VBA project window? I want to change the order around so that it matches the actual document, not alphabetical.

And on a side note/question, is there a way to export/save a VBA project as a word document so that I have a back-up of the code that I can easily copy/paste in the event of a loss of the code??? I found I can print it to PDF, but it doesn't allow me to select the text to copy/paste it.
Thanks!
 
Last edited:

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Maybe like this

Code:
Sub ChangeCodeNames()
Dim i As Long
For i = 1 To Worksheets.Count
    ActiveWorkbook.VBProject.VBComponents(Worksheets(i).CodeName).Properties("_CodeName") = "X" & i
Next i
For i = 1 To Worksheets.Count
    ActiveWorkbook.VBProject.VBComponents(Worksheets(i).CodeName).Properties("_CodeName") = "Sheet" & i
Next i
End Sub
 
Upvote 0
On your side note you can use File > Export to save a module as a .bas file.
 
Upvote 0
With the code I am getting this error:
"Programmatic Access to Visual Basic Project is not trusted"

And if I have the entire VBAProject selected (instead of just a single sheet/module) the export option is grayed out.
 
Upvote 0
Ok, the code you posted works on renaming the sheets in the VBA Project window, but I am hoping to have it use the workbook and put it in the order that it appears in the workbook (Home, Index, etc). The sheets are not in order in the workbook and in the project it keeps putting the sheets in alpha. order (sheet1, sheet11, sheet12, sheet2, sheet20, etc instead of sheet1,sheet2,sheet3,etc).
 
Upvote 0
Then perhaps

Code:
Sub ChangeCodeNames()
Dim i As Long
For i = 1 To Worksheets.Count
    ActiveWorkbook.VBProject.VBComponents(Worksheets(i).CodeName).Properties("_CodeName") = Worksheets(i).Name
Next i
End Sub

BTW, this is not "simple" :)
 
Upvote 0
I found a solution.. its going to take a little while, but it will work. I am changing the codenames in the properties box for each sheet. That seems to work.
 
Upvote 0
lol. I was hoping it was something like right click here and select order... or something like that... lol
Thanks for the help!
 
Upvote 0
Anyone know if there is a way to use this code:
Code:
Sub ChangeCodeNames()
Dim i As Long
For i = 1 To Worksheets.Count
    ActiveWorkbook.VBProject.VBComponents(Worksheets(i).CodeName).Properties("_CodeName") = "Sheet00" & i
Next i
End Sub

but when it gets to sheet 10 have it change to "Sheet0" & i? That way it will list them in proper order (001-009, 010,011, etc)
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,736
Members
452,940
Latest member
Lawrenceiow

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top