Using code to name userform

Jonnyoforem

New Member
Joined
May 22, 2015
Messages
32
I've created a function that makes a new user form but when I try to name the user form I get the error; Run-Time error '75': Path/File access error. Here are the relevant portions of my code.

Code:
Function NewUserForm (Title)

Dim TempForm As Object

'Hide VBE window to prevent screen flashing
Application.VBE.MainWindow.Visible = False

'Create the UserForm
Set TempForm = ThisWorkbook.VBProject.VBComponents.Add (3)
TempForm.Name = Title

End Function

In my own personal troubleshooting here's what I've found.

If I do the following it works fine
Code:
TempForm.Name = "Maintenance"

I want the person calling the function to be able to name the user form though.

I also tried the following and it gave me the same Run-Time error 75
Code:
Function NewUserForm (Title)

Dim TempForm As Object
Dim tite As String

'Hide VBE window to prevent screen flashing
Application.VBE.MainWindow.Visible = False

'Create the UserForm
Set TempForm = ThisWorkbook.VBProject.VBComponents.Add (3)
TempForm.Name = tite

End Function

Thanks in advance for any help!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Try...

Code:
TempForm.Properties("Name") = Title

Hope this helps!
 
Upvote 0
Sorry, actually your code works fine for me...
 
Last edited:
Upvote 0
Alright I can shed new light on the situation, any help would be fantastic. I can use this code to create the user form one time and one time only. This means if I try to create another user form with the same name I get the error I mentioned in my first post. Here's the annoying part. Even if I manually remove the user form from the vba project window I still can't create another user form with that name using this method.

Anyone know if there's a way to programmatically disable or remove user forms I've created in the past so I can keep testing my code?
 
Upvote 0
According to the following article, you cannot re-use the name of a UserForm due to a bug...

https://support.microsoft.com/en-us/kb/244238

However, after doing some testing, it looks like the name can be re-used as long as the workbook is saved first by adding the following line of code..

Code:
ThisWorkbook.Save

Hope this helps!
 
Upvote 0
Well I'm glad it's a bug, I thought I was going crazy. Thanks for doing the research and for all your help Domenic. It's greatly appreciated. For anyone looking at this thread in the future, another workaround is to just close excel after removing the user form. You can then create another one with the same name.
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,236
Members
448,555
Latest member
RobertJones1986

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