PDA

View Full Version : Sleeper: Copy vba macros



lior03
07-03-2005, 12:48 PM
Took advantage of a procedure I found in cpearson site.

The aim is to copy the entire vba code of a workbook to another.

The new code is

Sub CopyAllModules2()
Dim FName As String
Dim VBComp As VBIDE.VBComponent
Dim x As String
x = InputBox("specify workbook")
With ActiveWorkbook
FName = .Path & "\code.txt"
If Dir(FName) <> "" Then
Kill FName
End If
For Each VBComp In .VBProject.VBComponents
If VBComp.Type <> vbext_ct_Document Then
VBComp.Export FName
Workbooks(x).VBProject.VBComponents.Import FName
Kill FName
End If
Next VBComp
End With
End Sub

I want the user to specify to which workbook he wants to copy.
many thanks

Bob Phillips
07-03-2005, 01:38 PM
Took advantage of a procedure I found in cpearson site.

The aim is to copy the entire vba code of a workbook to another.

It seems to do the job. What is the problem?