LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Removing & Importing a macro module

I have several macros in Module3. Several workbooks use the module. When i
make changes to the code, I copy the module to a folder for import into the
other workbooks. The "update" module resides in Module1. The problem is
this - when I select "Update Macro" (from a user menu) the Module 1 macros
run. It is supposed to delete Module3 and then Import the new module (file
name *.bas) that I have put in the current directory with the workbook.
However, it often does not delete Module3 but then adds Module31. When I
run Auto_Open I get and "Ambiuous" error message because Module3 is still
there. Here is the code I got from somebody in the newsgroup many months
ago.

How can I ensure that Module3 is deleted/removed and that the import is
named Module3 and not Module31?

==================
Sub UpdateCode()
FName = Dir("*.bas")

If Len(FName) = 0 Then
MsgBox "No Code files in the Directory"
Exit Sub
Else
Application.ScreenUpdating = False
Application.EnableEvents = False
Call DeleteModule
Call ImportModule (FName)
CodeFile = True
Call auto_open
End If

Application.ScreenUpdating = True
Application.EnableEvents = True
If CodeFile Then
MsgBox "Code has been Updated"
Kill "*.bas"
Else
MsgBox "Code has NOT been updated - file not found"
End If

End Sub
Sub ImportModule(Modname As Variant)
ActiveWorkbook.VBProject.VBComponents.Import Modname
Application.Visible = True


End Sub
Sub DeleteModule()
Dim VBComp As VBComponent
On Error Resume Next
'remove module if named Module3 or Module31
Set VBComp = ActiveWorkbook.VBProject.VBComponents("Module3")
ThisWorkbook.VBProject.VBComponents.Remove VBComp
Set VBComp = ActiveWorkbook.VBProject.VBComponents("Module31")
ThisWorkbook.VBProject.VBComponents.Remove VBComp

End Sub


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing Alan Beban's code on Arrays; Importing a module or a project Steve G Excel Worksheet Functions 4 August 27th 07 04:18 PM
Removing Module Protection Programatically Adam Excel Discussion (Misc queries) 8 April 17th 06 05:46 AM
Removing a module with a macro bb Excel Programming 1 December 22nd 04 02:07 PM
Removing a module with code KimberlyC Excel Programming 2 January 13th 04 09:51 PM
importing a module DJ Excel Programming 1 November 10th 03 04:58 AM


All times are GMT +1. The time now is 03:46 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"