Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Preventing macros in attachment
Hello All:
I am running into an issue that I can't seem to figure out no matter what I try. I have the below automated email macro that runs on selection, but when attaching the attachment the rest of the Macros are present creating too large of an attachment. How can I keep the macros from moving into the attachment in the programming below? Sub FIELDWORK95EMAILSUBMISSION() Dim FileExtStr As String Dim FileFormatNum As Long Dim Sourcewb As Workbook Dim Destwb As Workbook Dim TempFilePath As String Dim TempFileName As String Dim OutApp As Object Dim sh As Worksheet With Application .ScreenUpdating = False .EnableEvents = False End With Set Sourcewb = ActiveWorkbook 'Copy the sheets to a new workbook Sheets("Sheet1").Select Application.DisplayAlerts = False ActiveWindow.SelectedSheets.Delete Application.DisplayAlerts = True Sheets("Final Form").Visible = True Sheets("Final Form").Select Cells.Select Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Set Destwb = ActiveWorkbook Set sh = Sheets("Final Form") 'Determine the Excel version and file extension/format With Destwb If Val(Application.Version) < 12 Then 'You use Excel 97-2003 FileExtStr = ".xls": FileFormatNum = -4143 Else 'You use Excel 2007 'We exit the sub when your answer is NO in the security dialog that you only 'see when you copy a sheet from a xlsm file with macro's disabled. If Sourcewb.Name = .Name Then With Application .ScreenUpdating = True .EnableEvents = True End With MsgBox "Your answer is NO in the security dialog" Exit Sub Else Select Case Sourcewb.FileFormat Case 51: FileExtStr = ".xlsx": FileFormatNum = 51 Case 52: If .HasVBProject Then FileExtStr = ".xlsm": FileFormatNum = 52 Else FileExtStr = ".xlsx": FileFormatNum = 51 End If Case 56: FileExtStr = ".xls": FileFormatNum = 56 Case Else: FileExtStr = ".xlsb": FileFormatNum = 50 End Select End If End If End With ' 'Change all cells in the worksheets to values if you want 'For Each sh In Destwb.Worksheets Sheets("Final Form").Select With Sheets("Final Form").UsedRange .Cells.Copy .Cells.PasteSpecial xlPasteValues .Cells(1).Select End With Application.CutCopyMode = False Destwb.Sheets("Final Form").Select 'Next sh With Application.ReplaceFormat.Font .Subscript = False .ColorIndex = 2 End With Cells.Replace What:="0", Replacement:="0", LookAt:=xlWhole, SearchOrder _ :=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=True Sheets("Final Form").Select 'Save the new workbook/Mail it/Delete it TempFilePath = Environ$("temp") & "\" TempFileName = Range("F5") Sheets("Final Form").Select Set OutApp = CreateObject("Outlook.Application") OutApp.Session.Logon Set OutMail = OutApp.CreateItem(0) With Destwb .SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum On Error Resume Next With OutMail .To = "" .CC = "" .BCC = "" .Subject = Range("F5") .Body = "Text goes here" .Attachments.Add Destwb.FullName 'You can add other files also like this '.Attachments.Add ("C:\test.txt") .Display 'or use .send End With On Error GoTo 0 .Close SaveChanges:=False End With 'Delete the file you have send Kill TempFilePath & TempFileName & FileExtStr Set OutMail = Nothing Set OutApp = Nothing With Application .ScreenUpdating = True .EnableEvents = True End With End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Preventing users from changing macros | Excel Discussion (Misc queries) | |||
Programmatically preventing macros issues | Excel Programming | |||
preventing macros from clearing the undo list | Excel Programming | |||
preventing disabling of macros | Excel Programming | |||
Parametrized Macros preventing other macros | Excel Programming |