VBA question
Apr. 4th, 2007 03:30 pmThis may be a long-shot, but...
Does anyone know how to use VBA to send an email with an embedded Excel chart? I've been wracking my brains, Googling obsessively and glaring at code, but to no avail. Recording the action as a Macro in Excel isn't helping because it doesn't show me doing the bit where I use File/Send To and definitely won't see anything I do in Outlook.
*sigh*
Got such a headache.
The good news is that the boss approved the VBA books I found so I'll be ordering them tonight and putting in an expenses claim. Woo!
Hopefully I'll at least find a hint about it in one of them. I feel rather less like Queen of Code than I usually do right now.
Guess I really need that pub trip with The Girls tonight.
Does anyone know how to use VBA to send an email with an embedded Excel chart? I've been wracking my brains, Googling obsessively and glaring at code, but to no avail. Recording the action as a Macro in Excel isn't helping because it doesn't show me doing the bit where I use File/Send To and definitely won't see anything I do in Outlook.
*sigh*
Got such a headache.
The good news is that the boss approved the VBA books I found so I'll be ordering them tonight and putting in an expenses claim. Woo!
Hopefully I'll at least find a hint about it in one of them. I feel rather less like Queen of Code than I usually do right now.
Guess I really need that pub trip with The Girls tonight.
no subject
Date: 2007-04-04 03:16 pm (UTC)Sub EmailTimesheet()
Dim appOutlook As Outlook.Application 'outlook application object
Dim otlkMessage As Outlook.MailItem 'message mail item
Dim otlkRecipient As Outlook.Recipient 'recipient for the mail message
Dim otlkAttachment As Outlook.Attachments 'attachment for the e-mail
On Error GoTo EmailTrap
'code to send the email to timesheets
'calling the check macro
TimesheetCheck
'if the timesheet is a ok, it is e-mailed
If boolTimeSheetAOk = True Then
'creating the outlook application
Set appOutlook = New Outlook.Application
'creating the outlook message
Set otlkMessage = appOutlook.CreateItem(olMailItem)
'creating the message subject
otlkMessage.Subject = "Timesheet " & Range("C3").Value & " W/C " & Range("C2").Value
'setting the recipient
Set otlkRecipient = otlkMessage.Recipients.Add("Timesheets")
'setting the recipient type
otlkRecipient.Type = olTo
'saving the current workbook
ThisWorkbook.Save
'creating the attachment object
Set otlkAttachment = otlkMessage.Attachments
'setting the attachment object to be the current workbook
otlkAttachment.Add ThisWorkbook.FullName
'displaying the current workbook
otlkMessage.Display
End If
EmailTrap:
If Err.Number <> 0 Then
MsgBox "An error has occured while attempting to Email the timesheet." & vbCrLf & vbCrLf & _
"Please contact Nic Mayer with the following information : " & vbCrLf & _
"Error Number = " & Err.Number & vbCrLf & "Error Description = " & _
Err.Description, vbCritical, "Email Timesheet Error"
End If
End Sub
no subject
Date: 2007-04-05 01:08 pm (UTC)no subject
Date: 2007-04-05 06:56 pm (UTC)no subject
Date: 2007-04-04 03:58 pm (UTC)I was so happy when we eventually found a ready rolled alternative for what I'd been trying to write!
no subject
Date: 2007-04-05 01:43 pm (UTC)Until that however...
We're trying to send an email with the chart embedded in the body. I can embed cell ranges in an HTML body and sort out plain text with no trouble, but this chart thing is defeating me *sigh* Hopefully the books that I've orderd will arrive some time next week so I can see whether there are any tips to get me started on this in those. So far, the only thing I can find when Googling is...a reference to one of the books that I've ordered :-)
no subject
Date: 2007-04-05 04:54 pm (UTC)?