Email Macro

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,057
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
My code works all fine but having error as Method Range of object _global failed
any suggestion as i am using office365

VBA Code:
Sub ImageRejection()
Sheets("Email Rejection").Select

    'Open a new mail item
    Dim outlookApp As Outlook.Application
    Set outlookApp = CreateObject("Outlook.Application")
    Dim outMail As Outlook.MailItem
    Set outMail = outlookApp.CreateItem(olMailItem)
    'Get its Word editor
    outMail.Display
   
   With outMail
    .To = Sheets("Email Rejection").Range("C3").Value
    .CC = Sheets("Email Rejection").Range("C4").Value
    .BCC = Sheets("Email Rejection").Range("C5").Value
    .Subject = Sheets("Email Rejection").Range("C6").Value
'    .Body = Sheets("Email Rejection").Range("C7").Value
'    .Display
   End With
   
    Dim wordDoc As Word.document
    Set wordDoc = outMail.GetInspector.WordEditor
    ' Copy and paste ranges from desired sheets
    PastePic wordDoc, "Email Rejection!C8:D8"

Sheets("Email Rejection").Select
End Sub
Private Sub PastePic(wordDoc As Word.document, rngRange As String)
    Dim r As Word.Range
    'Copy range of interest
    [B]Range(rngRange).Copy  --- here is error[/B]
    'Paste as picture in sheet and cut immediately
    ActiveSheet.Pictures.Paste.Cut
    Set r = wordDoc.Content
    r.collapse Direction:=wdCollapseEnd
    r.Paste
    i = wordDoc.InlineShapes.Count
    wordDoc.InlineShapes.Item(i).ScaleHeight = 85
    'wordDoc.InlineShapes.Item(I).ScaleWidth = 100
End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Range(rngRange) can't be SheetName!CellRange. You can either add another parameter to PastePic to send the worksheet name and rngRange separately or separate the SheetName and CellRange with this:
VBA Code:
Worksheets(Left(rngRange, InStr(1, rngRange, "!") - 1)).Range(Right(rngRange, Len(rngRange) - InStrRev(rngRange, "!"))).Copy
 
Upvote 0
Range(rngRange) can't be SheetName!CellRange. You can either add another parameter to PastePic to send the worksheet name and rngRange separately or separate the SheetName and CellRange with this:
VBA Code:
Worksheets(Left(rngRange, InStr(1, rngRange, "!") - 1)).Range(Right(rngRange, Len(rngRange) - InStrRev(rngRange, "!"))).Copy
kool its working perfect.
 
Upvote 0

Forum statistics

Threads
1,214,588
Messages
6,120,409
Members
448,959
Latest member
camelliaCase

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top