Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Send mail with macro ?

Hi

How i sent one graph from QV by e-mail with a macro?

Thank you

Regards

3 Replies
vikasmahajan

see this post

Re: export to excel and schedule mailing

Hope this resolve your issue.
If the issue is solved please mark the answer with Accept as Solution & like it.
If you want to go quickly, go alone. If you want to go far, go together.
sujeetsingh
Master III
Master III

kamakshisuram
Creator
Creator

Export and then send.

Below is sample Macro to export table called TB02 and send mail to the  Email Address contains in EmailAddress Variable . which is working.

function ExcelFile

  strDate = CDate(Date)

  strDay = DatePart("d", strDate)

  strMonth = DatePart("m", strDate)

  strYear = DatePart("yyyy", strDate)

  If strDay < 10 Then

    strDay = "0" & strDay

  End If

  If strMonth < 10 Then

    strMonth = "0" & strMonth

  End If

  GetFormattedDate = strMonth & "-" & strDay & "-" & strYear

  Set v = ActiveDocument.Variables ("EmailAddress")

  Email=v.GetContent.String

Path = "C:\EXCEL\OnRequest\"

FileName = "TESTCode_Data" & GetFormattedDate  & ".xlsx"

set XLApp = CreateObject("Excel.Application")

XLApp.Visible = False

set XLDoc = XLApp.Workbooks.Add

ActiveDocument.GetSheetObject("TB02").CopyTableToClipboard true

XLDoc.Sheets(1).Paste()

XLDoc.Sheets(1).Columns("A:L").EntireColumn.AutoFit

XLDoc.Sheets(1).Columns("A:A").ColumnWidth = 17

XLDoc.Sheets(1).Columns("B:B").ColumnWidth = 17

XLDoc.Sheets(1).Columns("C:C").ColumnWidth = 17

XLDoc.Sheets(1).Columns("D:D").ColumnWidth = 17

XLDoc.Sheets(1).Columns("E:E").ColumnWidth = 17

XLDoc.Sheets(1).Columns("F:F").ColumnWidth = 17

XLDoc.Sheets(1).Columns("G:G").ColumnWidth = 17

XLDoc.Sheets(1).Columns("H:H").ColumnWidth = 17

XLDoc.Sheets(1).Columns("I:I").ColumnWidth = 17

XLDoc.Sheets(1).Columns("J:J").ColumnWidth = 17

XLDoc.Sheets(1).Columns("K:K").ColumnWidth = 17

XLDoc.Sheets(1).Columns("L:L").ColumnWidth = 17

XLDoc.Sheets(1).Name = "Export"

XLDoc.SaveAs Path & FileName

XLApp.Quit

Set myApp = CreateObject ("Outlook.Application")

Set myMessage = myApp.CreateItem(olMailItem)

myMessage.BodyFormat = 3 'Outlook.OlBodyFormat.olFormatRichText

myMessage.To = Email

myMessage.Attachments.Add "C:\EXCEL\OnRequest\" & FileName

myMessage.Subject = "TEST Codes Report " & Date()

  myMessage.Body = "Hi Team, " & vbCrLf & "Please find the requested data for TEST Codes and let us know incase of any issues."

myMessage.Send

Set myMessage = Nothing

Set myApp = Nothing

Set myInspector = Nothing

Set myDoc = Nothing

end function