Help with copy macro module when mailing sheet

wisemank

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

Forum statistics

Threads
1,082,099
Messages
5,363,129
Members
400,720
Latest member
Pettel

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top