ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Removing & Importing user forms via code? (https://www.excelbanter.com/excel-programming/317561-removing-importing-user-forms-via-code.html)

R-Enemy[_3_]

Removing & Importing user forms via code?
 

Can I programmatically remove a user form and then import a user from?

The reason is I have a many workbooks that all use the same form and I
updated the code in one of the workbooks and I want to update all the
others without having to manually open each one, then open VBA, then
hit remove and then import. This would take way too long.

Thanks for any help.


--
R-Enemy
------------------------------------------------------------------------
R-Enemy's Profile: http://www.excelforum.com/member.php...o&userid=16732
View this thread: http://www.excelforum.com/showthread...hreadid=319362


Chip Pearson

Removing & Importing user forms via code?
 
Try something like the following:

With ActiveWorkbook.VBProject.VBComponents
.Remove .Item("UserForm1")
.Import Filename:="C:\whatever\userform1.frm"
End With

See www.cpearson.com/excel/vbe.htm for more details.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"R-Enemy" wrote in message
...

Can I programmatically remove a user form and then import a
user from?

The reason is I have a many workbooks that all use the same
form and I
updated the code in one of the workbooks and I want to update
all the
others without having to manually open each one, then open VBA,
then
hit remove and then import. This would take way too long.

Thanks for any help.


--
R-Enemy
------------------------------------------------------------------------
R-Enemy's Profile:
http://www.excelforum.com/member.php...o&userid=16732
View this thread:
http://www.excelforum.com/showthread...hreadid=319362




R-Enemy[_5_]

Removing & Importing user forms via code?
 
I'm still having a couple small problems...

1. It's not letting me remove a form and then import the new form right
away. It will remove the form but then give the error that the name exists
and can't import the new form. But, it will import the form the next time
through the Sub. (I'm using On Error Resume Next in case the form never
existed in the first place.)

2. Doing the same thing for a module it removes the module just fine but on
the import it adds a 1 to the module name, ex. "updater1" when it should be
just "updater"

Here's some of the code that I use:

Sub checkUpdates()
...
'If there's a newer version then...

'base has been set as Activeworkbook

Dim VBComp As Object
Set VBComp = base.VBProject.VBComponents("updater")
base.VBProject.VBComponents.Remove VBComp
base.VBProject.VBComponents.Import "K:\C-REPORT\VersionUpdate\updater.bas"

'this sub is contained inside updater
runUpdates

End Sub

Sub runUpdates()
On Error Resume Next

'up has been set to a workbook that tells what to remove,
'and the path of the file to be imported

Do While up.Sheets("Start").Cells(row, 1) < ""
Set VBComp = base.VBProject.VBComponents(up.Sheets("Start").Cel ls(row, 2))
base.VBProject.VBComponents.Remove VBComp
base.VBProject.VBComponents.Import up.Sheets("Start").Cells(row, 3)
row = row + 1
Loop

End Sub

I hope some of this makes sense.

Thanks for any help.

"Chip Pearson" wrote:

Try something like the following:

With ActiveWorkbook.VBProject.VBComponents
.Remove .Item("UserForm1")
.Import Filename:="C:\whatever\userform1.frm"
End With

See www.cpearson.com/excel/vbe.htm for more details.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



All times are GMT +1. The time now is 12:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com