<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Macro to export data to excel and send in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Macro-to-export-data-to-excel-and-send/m-p/1155428#M904568</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am new to QlikView and want to make a macro that would automatically copy/paste data from yesterday to excel, which would then be sent to MS.Outlook both as an attachment and as a picture in the E-mail's body section. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;While writing the macro and searching through forums for answers I stumbled on three roadblocks:&lt;/P&gt;&lt;P&gt;1. How can I make my macro check beforehand, whether yesterday's data has been loaded ? (There is one entry that is generated and could be used as a reference) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. At the beginning of a new month, the macro should still take last month's data, how could I structure the "IF/THEN" argument to help with this problem? (e.g. check if the "Day" filter selection has only 1 day and thus the macro understands that it should take last month)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. is it possible and, if it is, how could I paste the tables either from QV or Excel to Outlook's E-mail body section?&lt;/P&gt;&lt;P&gt;(Maybe there is a way to directly change the Email body through VBScript?)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since the code is quite long, I have attached a dummy file with it. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you beforehand for your invested time!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yours faithfully,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Arturs A.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 25 Nov 2020 16:16:04 GMT</pubDate>
    <dc:creator />
    <dc:date>2020-11-25T16:16:04Z</dc:date>
    <item>
      <title>Macro to export data to excel and send</title>
      <link>https://community.qlik.com/t5/QlikView/Macro-to-export-data-to-excel-and-send/m-p/1155428#M904568</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am new to QlikView and want to make a macro that would automatically copy/paste data from yesterday to excel, which would then be sent to MS.Outlook both as an attachment and as a picture in the E-mail's body section. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;While writing the macro and searching through forums for answers I stumbled on three roadblocks:&lt;/P&gt;&lt;P&gt;1. How can I make my macro check beforehand, whether yesterday's data has been loaded ? (There is one entry that is generated and could be used as a reference) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. At the beginning of a new month, the macro should still take last month's data, how could I structure the "IF/THEN" argument to help with this problem? (e.g. check if the "Day" filter selection has only 1 day and thus the macro understands that it should take last month)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. is it possible and, if it is, how could I paste the tables either from QV or Excel to Outlook's E-mail body section?&lt;/P&gt;&lt;P&gt;(Maybe there is a way to directly change the Email body through VBScript?)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since the code is quite long, I have attached a dummy file with it. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you beforehand for your invested time!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yours faithfully,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Arturs A.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Nov 2020 16:16:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Macro-to-export-data-to-excel-and-send/m-p/1155428#M904568</guid>
      <dc:creator />
      <dc:date>2020-11-25T16:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to export data to excel and send</title>
      <link>https://community.qlik.com/t5/QlikView/Macro-to-export-data-to-excel-and-send/m-p/1155429#M904569</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Okay, so I managed to solve it all by myself.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. I made a new variable to sum the contents of the data stream that is being updated and it looks something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If ActiveDocument.Variables("PrevDay").GetContent.String &amp;gt; 0 Then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Call GenerateMailReport&lt;/P&gt;&lt;P&gt;else&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Msgbox "Yesterday's Data not available!!"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. Simply made a new variable that is =("CurrentDate"-1) and after a if/then analysis I prompt to use it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;set y=ActiveDocument.Fields("M1")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set m=ActiveDocument.Fields("D1")&lt;/P&gt;&lt;P&gt;&amp;nbsp; y.Select ActiveDocument.Evaluate("Month(num(today()))")&lt;/P&gt;&lt;P&gt;&amp;nbsp; m.Select "&amp;gt;= 1" &amp;amp; "&amp;lt;=" &amp;amp; ActiveDocument.Evaluate("num(day(today()))")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; If ActiveDocument.Variables("nMonth").GetContent.String = 1 Then '&amp;lt;----if the number of selected days is 1, then start the magic&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; y.Select ActiveDocument.Variables("PrevMonth").GetContent.String '&amp;lt;------Check the variable that has the prev. month selected&lt;/P&gt;&lt;P&gt;&amp;nbsp; m.Select "&amp;gt;= 1" &amp;amp; "&amp;lt;=" &amp;amp; ActiveDocument.Evaluate("num(day(today()-1))") '&amp;lt;------- selected the whole previous month (if there are daily selections)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3. From the numerous possibilities I decided to export QV tables as images and then add them to the e-mail's body.&lt;/P&gt;&lt;P&gt;Export Images:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ActiveDocument.GetSheetObject("ObjectID").Restore '&amp;lt;------ The table has to be open in order to be exported&lt;/P&gt;&lt;P&gt;&amp;nbsp; ActiveDocument.GetApplication.WaitForIdle '&amp;lt;-------- sometimes the script is working so fast, that it does not export&lt;/P&gt;&lt;P&gt;&amp;nbsp; ActiveDocument.GetSheetObject("ObjectID").ExportBitmapToFile "C:\Path\FileName.PNG"&lt;/P&gt;&lt;P&gt;&amp;nbsp; ActiveDocument.GetSheetObject("ObjectID").Minimize&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Add to outlook:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;objMail.body = ("EmailBody")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; objMail.HTMLBODY = "&amp;lt;HTML&amp;gt;&amp;lt;BODY&amp;gt;"&amp;lt;img align=baseline border=1 hspace=2 src='C:\Path\FileName.png'&amp;gt;"&amp;lt;/BODY&amp;gt;&amp;lt;/HTML&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, I can't seem to be able to get the Macro to filter the last month if it has selected the first day of a new month.&lt;/P&gt;&lt;P&gt;Any assistance on this?&lt;/P&gt;&lt;P&gt;This is my current choice of script:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;set y=ActiveDocument.Fields("M1")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set m=ActiveDocument.Fields("D1")&lt;/P&gt;&lt;P&gt;&amp;nbsp; y.Select ActiveDocument.Evaluate("Month(num(today()))")&lt;/P&gt;&lt;P&gt;&amp;nbsp; m.Select "&amp;gt;= 1" &amp;amp; "&amp;lt;=" &amp;amp; ActiveDocument.Evaluate("num(day(today()-6))") '&amp;lt;---- manually added to set the date at 1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; If ActiveDocument.Variables("nMonth").GetContent.String = 1 Then&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; y.Select ActiveDocument.Evaluate("Month(num(today()-1))") '&amp;lt;-------- doesn't select the previous month.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Jul 2016 10:55:44 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Macro-to-export-data-to-excel-and-send/m-p/1155429#M904569</guid>
      <dc:creator />
      <dc:date>2016-07-07T10:55:44Z</dc:date>
    </item>
  </channel>
</rss>

