Hello all,
I am adjusting a macro written by an ex colleague and im stuck with the following.
This macro selects a range and pastes it into and email using ActiveInspector.WordEditor. Now i cant seem to get the email text to appear before the range is pasted into the email body. I have used the Range.InsertBefore method but this does not work. Any help is much appriciated.
I am adjusting a macro written by an ex colleague and im stuck with the following.
This macro selects a range and pastes it into and email using ActiveInspector.WordEditor. Now i cant seem to get the email text to appear before the range is pasted into the email body. I have used the Range.InsertBefore method but this does not work. Any help is much appriciated.
VBA Code:
Sub email_reports_pt_res(autoSend As Boolean, strCC As String)
Dim aOutlook As Object
Dim aEmail As Object
Dim time As Integer
Dim emailText As String
Dim emailSignature As String
Dim wDoc As Object
'Outlook objects initialization
Set aOutlook = CreateObject("Outlook.Application")
Set aEmail = aOutlook.CreateItem(0)
aEmail.Display
Set wDoc = aOutlook.ActiveInspector.WordEditor
'Setting the signature
emailSignature = "Best Regards, "
emailText = vbCrLf & vbCrLf & vbCrLf & "Please find above information regarding Interval Report from " & Worksheets("Email Templates").Range("C21") & vbCrLf & vbCrLf & emailSignature
'Setting the email properties
aEmail.Importance = 1
aEmail.Subject = "Email Dashboard "
aEmail.To = "<email@email.com>; <email@email.com>"
aEmail.CC = "<email@email.com>; <email@email.com>"
'Signature bound
wDoc.Range.InsertBefore (emailText)
'Copy Dashboard
Worksheets("Email Templates").Range("B2:AB34").CopyPicture Appearance:=xlScreen, Format:=xlPicture
wDoc.Range.Paragraphs(1).Range.Paste
'Resizing all the images for a fixed width and length
For Each IShape In wDoc.InlineShapes
IShape.LockAspectRatio = True
IShape.Height = IShape.Height * 1.4
IShape.Width = IShape.Width * 1.5
Next IShape
'Disabling the default signature
DeleteSig aEmail
'Sending Mode
If (autoSend) Then
'Autosend the email
aEmail.Display
End If
'Clearing memory
Set aOutlook = Nothing
Set aEmail = Nothing
Set wDoc = Nothing
End Sub