I use the following code to save a copy of my active workbook and add the current date to the name of the file. Here's and example of a file name the code generates: Daily Schedule For 2004-09-14 Tuesday.xls.
Here's my problem. This procedure is run daily so there are 100's of files in the same folder. I want to email the file containing today's date in the name. How do I modify the following code to do that? I bolded the part that I think needs to be modified.
Help is appreciated as always. Thanks in advance to all of you VBA gurus.
Rich (BB code):
Sub CopyForProduction()
Call DeleteShapes
'Sheets("Attainment").Select
' ActiveWindow.SelectedSheets.Delete
Dim da, mot, daypa, newfor As String
Dim sp As Integer
da = Date
da = Trim$(da)
sp = InStr(da, "/")
mot = Right$("0" & Left$(da, sp - 1), 2)
daypa = Mid$(da, sp + 1)
sp = InStr(daypa, "/")
daypa = Right$("0" & Left$(daypa, sp - 1), 2)
'IF len(da
newfor = Right$(da, 4) & "-" & mot & "-" & daypa & " " & WeekdayName(Weekday(Date))
ChDir "c:\sched"
ActiveWorkbook.SaveAs FileName:= _
"c:\sched\Daily Schedule For " & newfor & ".xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:= _
False, CreateBackup:=False
'Call savexpad
Range("B5").Select
End Sub
Here's my problem. This procedure is run daily so there are 100's of files in the same folder. I want to email the file containing today's date in the name. How do I modify the following code to do that? I bolded the part that I think needs to be modified.
Rich (BB code):
Sub sendmail()
'Open a new blank message in Outlook
Set myol = New Outlook.Application
Set myitem = myol.CreateItem(olMailItem)
myitem.To = Variable_to
myitem.CC = Variable_cc
'myitem.BCC = ""
myitem.Subject = "Daily Production Schedule" 'Variable_subject
myitem.Body = "The most current schedule is attached."
Set myAttachments = myitem.Attachments
myAttachments.Add "C:/Sched/filename.xls", olByValue, , "Daily Schedule"
myitem.Display ':- if you want outlook to display the mail message for you to check/add to before you send
'or use
'myitem.send :-if you just want your application to send email automatically.
End Sub
Help is appreciated as always. Thanks in advance to all of you VBA gurus.