I need help with the code below. My macro copies a sheet from a masterworkbook and sends a copy of each sheet for the respective disciplines to complete. I added a userform to make their work easier, but the macro/module doesn't go with the new sheet. Can someone look at this code and help me determine where and when the module import needs to take place? The area is in bold below. I recieve no errors, but I don't get the macro either. Thanks in advance.
'Working in 97-2010
Dim sh As Worksheet
Dim wb As Workbook
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim TempFilePath As String
Dim TempFileName As String
Dim i As Long
TempFilePath = Environ$("temp") & "\"
If Val(Application.Version) < 12 Then
'You use Excel 97-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'You use Excel 2007-2010
FileExtStr = ".xlsm": FileFormatNum = 52
End If
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
For Each sh In ThisWorkbook.Worksheets
If sh.Range("A1").Value Like "?*@?*.?*" Then
sh.Copy
Set wb = ActiveWorkbook
TempFileName = "Sheet " & sh.Name & " of " _
& ThisWorkbook.Name & " " _
& Format(Now, "dd-mmm-yy h-mm-ss")
With wb
.SaveAs TempFilePath & TempFileName & FileExtStr, _
FileFormat:=52 'FileFormatNum
On Error Resume Next
For i = 1 To 3
.SendMail sh.Range("A1").Value, _
"This is the V.C.E. & M BICEEPR Walk request"
If Err.Number = 0 Then Exit For
Next i
On Error GoTo 0
.Close SaveChanges:=False
End With
' Delete any old stray copies of the module13
On Error Resume Next
Kill ("C:\module13.bas")
' Export Module 13
ActiveWorkbook.VBProject.VBComponents("module13").Export ("c:\module13.bas")
Application.VBE.ActiveVBProject.VBComponents.Import ("c:\module13.bas")
'Next x
Kill ("C:\module13.bas")
'Delete the file you have sent
Kill TempFilePath & TempFileName & FileExtStr
End If
Next sh
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
'Working in 97-2010
Dim sh As Worksheet
Dim wb As Workbook
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim TempFilePath As String
Dim TempFileName As String
Dim i As Long
TempFilePath = Environ$("temp") & "\"
If Val(Application.Version) < 12 Then
'You use Excel 97-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'You use Excel 2007-2010
FileExtStr = ".xlsm": FileFormatNum = 52
End If
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
For Each sh In ThisWorkbook.Worksheets
If sh.Range("A1").Value Like "?*@?*.?*" Then
sh.Copy
Set wb = ActiveWorkbook
TempFileName = "Sheet " & sh.Name & " of " _
& ThisWorkbook.Name & " " _
& Format(Now, "dd-mmm-yy h-mm-ss")
With wb
.SaveAs TempFilePath & TempFileName & FileExtStr, _
FileFormat:=52 'FileFormatNum
On Error Resume Next
For i = 1 To 3
.SendMail sh.Range("A1").Value, _
"This is the V.C.E. & M BICEEPR Walk request"
If Err.Number = 0 Then Exit For
Next i
On Error GoTo 0
.Close SaveChanges:=False
End With
' Delete any old stray copies of the module13
On Error Resume Next
Kill ("C:\module13.bas")
' Export Module 13
ActiveWorkbook.VBProject.VBComponents("module13").Export ("c:\module13.bas")
Application.VBE.ActiveVBProject.VBComponents.Import ("c:\module13.bas")
'Next x
Kill ("C:\module13.bas")
'Delete the file you have sent
Kill TempFilePath & TempFileName & FileExtStr
End If
Next sh
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub