Help with copy macro module when mailing sheet

wisemank

Board Regular
Joined
Jun 21, 2010
Messages
127
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
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Forum statistics

Threads
1,171,885
Messages
5,878,044
Members
433,313
Latest member
Excelnoob69

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top