Exporting VB Forms Automatically

A

aVBgrad

I am trying to export several Forms that I have created using VBEditor. I am
not aware if this is possible or the correct syntax to export the form to a
text file and then upload the form to another worksheet automatically. I
have approximately 40+ spreadsheets that need to have the same form in each
file. I have done this successfully with Modules but not with Forms. Is it
possible to export and import automatically? Here is a sample of the syntax
that I used for the modules......

With Workbooks(RollUpProg)
FName = .Path & "\code.txt"
.VBProject.VBComponents("InventoryWalk2").Export FName
End With
Workbooks(datafilename).VBProject.VBComponents.Import FName
 
L

Leith Ross

Hello aVBgrad,

The syntax is almost identical to importing or exporting a module. Just
change UserForm1 to the form name you are using. The file name must end
in .frm

'This code must be run from the Workbook the Forms are in to be
exported.
With Workbooks(RollUpProg)
FName = .Path & "\Test Form.frm"
..VBProject.VBComponents("UserForm1").Export FName
End With

'This code must be run from the Workbook that it is in to import the
form.
Workbooks(datafilename).VBProject.VBComponents.Imp ort FName

Sincerely,
Leith Ross
 
A

aVBgrad via OfficeKB.com

Thanks....that did the trick. But do you know how to remove or delete a from.
I can do this with a module but am having issues with a Form. Here is the
syntaxt I use for a module

Set VBComp = Workbooks(RollUpProg).VBProject.VBComponents("UserForm1")
ActiveWorkbook.VBProject.VBComponents.Remove VBComp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top