Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Macro to export and mail

I am using following macro to export the chart as image and then send mail .

The image in mail body.

Sending as attachment, works fine but , image in mail body is an issue.

If I provide hardcoded path in src, then it works, but I want it dynamic. to exported file path.

Please help me out.

Here I get error as "Object required: '[string: "C:\USERS\841240\DOWN"]'" while assigning value to variable "Path"

public function ExportImage

  ActiveDocument.GetApplication.WaitForIdle

  ActiveDocument.GetSheetByID("DASH").Activate

  vFolder = ActiveDocument.GetVariable("vExportFolder").GetContent().String

  set obj = ActiveDocument.GetSheetByID("DASH")

  ActiveDocument.GetApplication.WaitForIdle

  fileName = "ExportScreen_" & replace(replace(replace(date() & "_" & time(), "/", ""), ".", ""), ":", "") & ".png"

  ActiveDocument.GetApplication.WaitForIdle

  obj.ExportBitmapToFile vFolder & fileName

  set obj = ActiveDocument.GetSheetObject("EXPORT")

  ActiveDocument.GetApplication.WaitForIdle

  fileName = "ExportScreen_" & replace(replace(replace(date() & "_" & time(), "/", ""), ".", ""), ":", "") & ".png"

  ActiveDocument.GetApplication.WaitForIdle

  obj.ExportBitmapToFile vFolder & fileName

  mSendMail vFolder , fileName

end function

function mSendMail(vFolder , fileName)

          Dim objOutlk 'Outlook

          Dim objMail 'Email item

          Dim strMsg

          dim strMailTo

          dim sString

          dim oldFormat

          Dim Rng

          Const olMailItem = 0

          Const CdoReferenceTypeName = 1

          Set objOutlk = CreateObject("Outlook.Application")

          Set objMail = objOutlk.createitem(olMailItem)

          Set Rng = Nothing

          set Path =  vFolder & fileName

          objMail.To = "nitingupta@eaton.com"

          objMail.subject = "TEST"

         ' ActiveDocument.ActiveSheet.CopyBitmapToClipboard true

           objMail.attachments.add(vFolder & fileName)

          strMsg = "This is an automatic generated email from QlikView for TEst Purpose."

          objMail.body = strMsg

    objMail.HTMLBODY = "<HTML><BODY><img align=baseline border=0 hspace=0 src= 'Path'</BODY></HTML>"

            objMail.Send

          Set objMail = Nothing

          Set objOutlk = Nothing

           Msgbox  Path

    Msgbox " Mail delivered"

end function

0 Replies