programing

Duplicate User Form in Excel VBA

newstyles 2023. 6. 18. 12:26

Duplicate User Form in Excel VBA

I want to duplicate form in excel vba, this is necessary because I have applied some formatting to the form and now want all my forms to have the same formatting.

In this way I'll have to only change the "names" of command button in each form and nothing else.

I tried exporting the form and then importing it, but it gives an error saying "The name is already in use"

Any help would be appreciated.

Temporarily change the form name, export it, change the name back, then import the UserForm file. That way they do not match.

Another method:
With your desired workbook open...
Create a new workbook (Ctrl+N) (by default called Book1) then
within the VBA Project window (Ctrl+R),
drag the form you want, and
drop it onto the new workbook VBAProject(Book1). (a small "plus" under the cursor indicates you're doing it right.)
Now Doubleclick the form you just created. (You may need to click the "plus" in front of the Forms folder to display it) and then
in the Properties window (F4) change the "Name" to something unique.
Now back in the VBA Project window
drag and drop this new form back to your original VBAProject.
Done.

For multiple forms repeat the last 2 steps.

ReferenceURL : https://stackoverflow.com/questions/16817764/duplicate-user-form-in-excel-vba