Im stuck,
Apart from locking a file I've spent a good few nights working on (by duplicating a Sub name in a module - sleep deprivation is never a good thing) I find my self stuck setting an application.workbooks(file
name&path)
I have tried a number of combinations of the folder/filepath etc but no joy
I have added the code if anyone can spot the error Ive points a plenty - Im sure its something vsimple... as usual
also if anyone knows how to uncrash an excel file that is well and truly skuppered - ie it wont open at all (when you open it in Visual Basic Editor - it freezes as soon as th code window with the duplicated sub name pops up - so no guesses where the problem is there)
Points galore for that one too :)
Dealines are looming and sleep still evades ... all help gratefully accepted...
code is:
Option Explicit
Sub CopyModule()
' copies a module from one workbook to another
' example:
Dim strFolder As String
Dim strTempFile As String
Dim wb1 As Excel.Application
Dim wb2 As Excel.Application
Dim TargetFile As String
Dim SourceFile As String
Dim TargetWB As Workbook
Dim SourceWB As Workbook
Dim strModuleName As String
Dim strModuleName1 As String
Dim strModuleName2 As String
Dim strModuleName3 As String
Dim strModuleName4 As String
Dim strModuleName5 As String
Dim strModuleName6 As String
Dim module As Integer
SourceFile = "TS4.0 Control Panel - Backup.xls"
TargetFile = "Code Dump.xls"
Set wb1 = CreateObject("Excel.Applic
ation")
Set wb2 = CreateObject("Excel.Applic
ation")
strFolder = "C:\Users\lrc\Desktop\TS4.
0 Stable"
Set TargetWB = wb1.Workbooks(strFolder & "\" & TargetFile)
Set SourceWB = wb2.Workbooks(strFolder & "\" & SourceFile)
strModuleName1 = "format_Control"
strModuleName2 = "format_Extracts"
strModuleName3 = "reportControl"
strModuleName4 = "format_Control"
strModuleName5 = "setParameters"
strModuleName6 = "Module1"
' If Len(strFolder) = 0 Then strFolder = CurDir
For module = 1 To 6
strModuleName = "strModuleName" & module
strFolder = strFolder & "\"
strTempFile = strFolder & strModuleName & ".bas"
On Error Resume Next
SourceWB.VBProject.VBCompo
nents(strM
oduleName)
.Export strTempFile
TargetWB.VBProject.VBCompo
nents.Impo
rt strTempFile
Kill strTempFile
On Error GoTo 0
Next module
MsgBox ("All Done")
End Sub