Good afternoon, I hope you're all well.
I've been searching here and other forums all day and can't find a soltuion to a problem I'm having.
I have a worksheet where I want the user to click a button, it filters the table by a particular criteria, highlights a range, copies that range as a picture, opens a new email and pastes that image in the body of the email along with some text.
I'm pretty much there, but the issue I'm having is, the picture is being cut off half way across once pasted.
If I manually copy as picture and paste to an email, it works no problem.
I've read time and time again that it might me down to Application.ScreenUpdating, but I don't have any of that in my code at the moment.
My code is as follows:
If anyone can point me in the right direction, it would be greatly appreciated.
Thank you.
Regards
Marhier.
I've been searching here and other forums all day and can't find a soltuion to a problem I'm having.
I have a worksheet where I want the user to click a button, it filters the table by a particular criteria, highlights a range, copies that range as a picture, opens a new email and pastes that image in the body of the email along with some text.
I'm pretty much there, but the issue I'm having is, the picture is being cut off half way across once pasted.
If I manually copy as picture and paste to an email, it works no problem.
I've read time and time again that it might me down to Application.ScreenUpdating, but I don't have any of that in my code at the moment.
My code is as follows:
Code:
Sub Notify()
'Outlook Variables
Dim oLookApp As Outlook.Application
Dim oLookItm As Outlook.MailItem
Dim oLookIns As Outlook.Inspector
'Excel Variables
Dim ExcRng As Range
Dim wsSheet As Worksheet, rRng As Range, sRnge As Range, fRng As Range
Set wsSheet = ActiveSheet
Set rRng = wsSheet.Range("A8:X1008")
Set sRng = wsSheet.Range("Y1")
Set fRng = wsSheet.Range("A8:P1008")
'Word Variables
Dim oWrdDoc As Word.Document
Dim oWrdRng As Word.Range
'Unprotect the sheet
ActiveSheet.Unprotect
'Filter the table
With rRng
.AutoFilter Field:=22, Criteria1:="O"
If .SpecialCells(xlCellTypeVisible).Address = .Rows(1).Address Then
MsgBox "There are no lines set as 'To Order' - Status 'O'."
wsSheet.AutoFilter.ShowAllData
ActiveSheet.Protect
Exit Sub
Else
End If
End With
On Error Resume Next
'Get the Active instance of Outlook
Set oLookApp = GetObject(, "Outlook.Applicaiton")
'If error, create a new instance of Outlook
If Err.Number = 429 Then
'Clear error
Err.Clear
'Create a new instance of outlook
Set oLookApp = New Outlook.Application
End If
'Cereate new email
Set oLookItm = oLookApp.CreateItem(olMailItem)
'Create a reference to Excel range
Set ExcRng = wsSheet.Range("A8:P1008")
With oLookItm
.To = "me@me.com"
.CC = ""
.BCC = ""
.Subject = sRng
.Body = "Hello, the following has been added to order."
'Display email
.Display
'Get the Active Inspector
Set oLookIns = .GetInspector
'Get Word Editor
Set oWrdDoc = oLookIns.WordEditor
'Specify the range in the document
Set oWrdRng = oWrdDoc.Application.ActiveDocument.Content
oWrdRng.Collapse Direction:=wdCollapseEnd
'Add paragraph and insert break
Set oWrdRng = oWdEditpor.Paragraph.Add
oWrdRng.InsertBreak
'Copy the Range
ExcRng.Copy
'Paste it
oWrdRng.PasteSpecial DataType:=wdPasteMetafilePicture
End With
ActiveSheet.Protect
End Sub
If anyone can point me in the right direction, it would be greatly appreciated.
Thank you.
Regards
Marhier.