I'm trying to figure out if it is possible to do a reload of a qvw file from a batch script and then, using a module on the report, output a straight table to a file and send it via email.
I've managed to create the batch script to reload the report and export the straight table no problem. The issue is the emailing part and trying to get it to work in combination with the batch script.
For some reason, if I reload the report with it open (just from the reload button) it works and the module sends the email. If I close the report and run the batch script then the report reloads (I see the progress pop-up box) but I don't get the email and the command prompt stays open. Below is the VBScript I'm using (by the way, I've been chopping it from various different web sites and posts here so may be a mess!):
if len(CStr(Month(Date()))) = 1 then
theDate = CStr(Day(Date())) & "0" & CStr(Month(Date())) & CStr(Year(Date()))
theDate = CStr(Day(Date())) & CStr(Month(Date())) & CStr(Year(Date()))
filename = "C:\Users\chris_johnson\Documents\Test " &theDate& ".xls"
sub ExportToExcel (filename)
Set o = ActiveDocument.GetSheetObject("LA01")
'theDate = CStr(Date())
'filename = "C:\Users\chris_johnson\Documents\Test " &theDate& ".xls"
set o = Nothing
varTo = "firstname.lastname@example.org"
varSubject = "Report"
varTextBody = "Please find report attached"
varAttachment = attachment
Set ObjSendMail = CreateObject("CDO.Message")
'This section provides the configuration information for the remote SMTP server.
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtpserv"
ObjSendMail.To = varTo
ObjSendMail.Subject = varSubject
ObjSendMail.From = "email@example.com"
' we are sending a text email.. simply switch the comments around to send an html email instead
'ObjSendMail.HTMLBody = "this is the body"
ObjSendMail.TextBody = varTextBody
Set ObjSendMail = Nothing
Can someone help me with trying to understand if (1) this is the right way to go about this and (2) how to change this script in order to get it to work with emailing from batch script.
I've had half a thought that maybe I should remove the emailing part from the VBScript and possibly put it into the batch script.