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

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
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,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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