Programmatically Rename a UserForm

BriargateExcel

New Member
Joined
Apr 13, 2020
Messages
13
Office Version
  1. 365
Platform
  1. Windows
I'm trying to rename a UserForm in my VBA code with:
ThisWorkbook.VBProject.VBComponents("UserForm1").Name="UserFormNew"
I get "Run-time Error '75': Path/File access error"
I would appreciate any suggestions.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
I ran your code without modifying anything and it successfully renamed the UserForm1 to UserFormNew. Perhaps you have some sort of access error. Have you tried this on a new worksheet?
 
Upvote 0
Are you running the code from inside the userform module or while the userform is loaded?
 
Upvote 0
rlv1: Thanks for your quick response!
I closed and re-opened the workbook and it ran fine.
This raises another question: why does close/re-open make it work?
 
Upvote 0
Jaafar Tribak: Thanks, also, for your quick reply!
I'm running it from a standard module. I create the form with:
ThisWorkbook.VBProject.VBComponents.Add(vbext_ct_MSForm)
Then attempt to rename the form.
As rlv1 suggested, I closed and re-opened the workbook. It works the first time and fails the second and successive times.
Again: why does close/re-open make it work? Very frustrating...
 
Upvote 0
Jaafar Tribak: Thanks, also, for your quick reply!
I'm running it from a standard module. I create the form with:
ThisWorkbook.VBProject.VBComponents.Add(vbext_ct_MSForm)
Then attempt to rename the form.
As rlv1 suggested, I closed and re-opened the workbook. It works the first time and fails the second and successive times.
Again: why does close/re-open make it work? Very frustrating...

Not sure why ... Maybe someone else here knows .
 
Upvote 0
It works if I remove the UserForm, save the workbook, and re-try.
It fails if I remove the UserForm and re-try without saving.
 
Upvote 0
On the 2nd attempt are you sure the fail is not because you have already renamed the user form and so

VBA Code:
ThisWorkbook.VBProject.VBComponents("UserForm1").Name="UserFormNew"

produces an error because there is no longer any "UserForm1"?
 
Upvote 0

Forum statistics

Threads
1,223,879
Messages
6,175,148
Members
452,615
Latest member
bogeys2birdies

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