Renaming VBA created forms after having deleted the first one with the same name

vimmi

New Member
Joined
Apr 30, 2018
Messages
3
Hi,

The aim was to have VBA create a new form upon request, rename it for ease of use in other code, collect data etc then delete it after to keep things clean.
Issue, although the occurrence if it happening are slim, is when the request is done twice and the code tries to rename the form with the same name. I get a "Path/File access error".

I'm guessing it's an excel issue with how it handles objects and names.

Code:
Sub create_get_mth_form()
    Dim frm As Object
    Set frm = ThisWorkbook.VBProject.VBComponents.Add(3)
    Debug.Print frm.Name
    frm.Name = "Get_Mth2"
End Sub

Although I'm now planning on adding a check to see if the form is there in the first place and only delete it on file close I would still be curious if there is anything that could be done and why it's happening?
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
I believe it some sort of bug. But you might be able to work around it by simply saving the worokbook before renaming it...

Code:
ThisWorkbook.Save
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,021
Members
452,374
Latest member
keccles

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