I have a workbook that is scheduled to run using MS Scheduled tasks. The code is inside this Workbook open and the file has digital signatures so no pop ups come up.
My problem is when I want to make a change and don't want any code exectued at start.
I thought I could hold the shift key down to disable the macro but it runs one loop and sends mail before stopping.
Is there something I am missing or another way to look at this?
There is a snip of code below as an example. I actually mail 28 files with the code and only included a short sample.
Private Sub Workbook_Open()
'This procedure Below will mail copies of the specific books.
Dim wb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim FileExtStr As String
Dim iMsg As Object
Dim iConf As Object
' Dim Flds As Variant
'MAIL # 1+++++++++++++++++++++++++
++++++++++
++++++++++
+++++++
ChDir "Q:\MIS\Aspect\Daily"
Workbooks.Open Filename:="Q:\MIS\AspectIV
\CCSC 452 - Current Customer.xls"
Set wb = ActiveWorkbook
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
'Make a copy of the file/Mail it/Delete it
TempFilePath = Environ$("temp") & "\"
TempFileName = wb.Name & " " & Format(Now - 1, "dd-mmm-yy")
FileExtStr = "." & LCase(Right(wb.Name, Len(wb.Name) - InStrRev(wb.Name, ".", , 1)))
wb.SaveCopyAs TempFilePath & TempFileName & FileExtStr
Set iMsg = CreateObject("CDO.Message"
)
Set iConf = CreateObject("CDO.Configur
ation")
With iMsg
Set .Configuration = iConf
.To = "Hele.com"
.CC = ""
.BCC = "mitch.com"
.From = "MrDa.com"
.Subject = "This is an automated mailing of report ccsc_452.xls"
.TextBody = "comments, Please Email Mitch."
.AddAttachment TempFilePath & TempFileName & FileExtStr
.Send
End With
Kill TempFilePath & TempFileName & FileExtStr
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
ActiveWorkbook.Save
ActiveWindow.Close
'MAIL # 2+++++++++++++++++++++++++
++++++++++
++++++++++
+++++++
ChDir "Q:\MIS\Aspect\Daily"
Workbooks.Open Filename:="Q:\MIS\AspectIV
\CCSC 454 - Current.xls"
Set wb = ActiveWorkbook
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
'Make a copy of the file/Mail it/Delete it
TempFilePath = Environ$("temp") & "\"
TempFileName = wb.Name & " " & Format(Now - 1, "dd-mmm-yy")
FileExtStr = "." & LCase(Right(wb.Name, Len(wb.Name) - InStrRev(wb.Name, ".", , 1)))
wb.SaveCopyAs TempFilePath & TempFileName & FileExtStr
Set iMsg = CreateObject("CDO.Message"
)
Set iConf = CreateObject("CDO.Configur
ation")
With iMsg
Set .Configuration = iConf
.To = "helre.com"
.CC = ""
.BCC = "mitccom"
.From = "MrDacom"
.Subject = "This is an automated mailing of Aspect report ccsc_454.xls"
.TextBody = " comments, Please Email Mitch."
.AddAttachment TempFilePath & TempFileName & FileExtStr
.Send
End With
Kill TempFilePath & TempFileName & FileExtStr
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
ActiveWorkbook.Save
ActiveWindow.Close
End Sub()
Start Free Trial