Hi,
I googled how to do this and came up with the following code. There are two subs, the first generates a "baby" report from a master document. At the end of the routine it is meant to call a sub to export a module of code from the source workbook to the newly created "baby" report.
I don't get any VBA errors but the module i want to export (module8) just not appear in the new workbook.
Any ideas? I'm not great in VBA!
I am running Excel 2010 in compatibility mode as the end users all have Excel 2003.
Thanks
J
Sub Create_Report()
'
' Create Latest Conversions File
'
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim Newbook As Workbook
Dim Thisbook As Workbook
Set Thisbook = ActiveWorkbook
Set Newbook = Workbooks.Add
' lots of code that moves some sheets into the new workbook from the source workbook
Call CopyModule(Thisbook, "Module8", Newbook)
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
And the below routine is meant to export the required module...
[/CODE] Sub CopyModule(SourceWB As Workbook, strModuleName As String, _
TargetWB As Workbook)
' copies a module from one workbook to another
Dim strFolder As String, strTempFile As String
strFolder = SourceWB.Path
If Len(strFolder) = 0 Then strFolder = CurDir
strFolder = strFolder & "\"
strTempFile = strFolder & "~tmpexport.bas"
On Error Resume Next
SourceWB.VBProject.VBComponents(strModuleName).Export strTempFile
TargetWB.VBProject.VBComponents.Import strTempFile
Kill strTempFile
On Error GoTo 0
End Sub[/CODE]
Bookmarks