willastrowalker
New Member
- Joined
- Aug 28, 2015
- Messages
- 9
there seem to be lots of codes for this out there and I'm really close to getting it figured out.. I have a workbook that has 26 sheets, I want to create a macro that saves all sheets as hardcodes (completed) and creates a draft email in outlook with each sheet as an attachment.
Created a loop to save all sheets as hardcodes, so that works fine, just need help with what I think is a minor tweak to create individual emails.
Everything works, but the attachments are all placed in the same email, and not in separate email drafts.. So I want 26 drafts with one attachment, not one draft with 26 attachments.
Created a loop to save all sheets as hardcodes, so that works fine, just need help with what I think is a minor tweak to create individual emails.
Everything works, but the attachments are all placed in the same email, and not in separate email drafts.. So I want 26 drafts with one attachment, not one draft with 26 attachments.
Code:
Sub Saveandemail()
Application.DisplayAlerts = False
Dim sname As String
Dim wsht As Worksheet
Dim wbnew As Workbook
Dim todaysdate As String
Dim wkshtname As String
Dim OutApp As Object
Dim Outmail As Object
Dim Emailaddress as string
Set OutApp = CreateObject("Outlook.Application")
Set Outmail = OutApp.CreateItem(0)
todaysdate = Format(Now, "MM-DD-YY")
For Each wsht In ActiveWorkbook.Sheets
wkstname = ActiveSheet.name
wsht.Copy
With ActiveSheet.UsedRange
.Value = .Value
End With
Set wbnew = ActiveWorkbook
sname = Range("g60").Value
emailaddress = Range("g61").value
With wbnew
.SaveAs "C:\filepath\" & wsht.name & "_" & todaysdate & ".xlsx"
With Outmail
.to = emailaddress
.CC = ""
.BCC = ""
.Subject = "emailing" & wkshtname
.Body = "Hi there"
.Attachments.Add wbnew.FullName
.Save
End With
wbnew.Close True
End With
Next wsht
Application.DisplayAlerts = True
End Sub