VBA Reference specific Cell Value from another workbook

rplohocky

Active Member
Joined
Sep 25, 2005
Messages
292
Office Version
  1. 365
Platform
  1. Windows
Hello,
Can someone look at this code and help me with a reference? I am trying to grab an email address from another open workbook and have it insert into the "TO:" location in the email. I'm getting stuck on what I'm doing wrong or what's missing. The email address is located in cell D33 which is in workbook ("6251 Vivint Rental Report.xlsm").

Code:
Sub EmailRentalReport6251()

    Dim mess_body As String, StrFile As String, StrPath As String
    Dim OutApp As Object
    Dim OutMail As Object
    Dim Rng As Range
    Dim WorkRng As Range



   '****************************************************
' THIS IS WHAT I AM USING TO REFERENCE THE OPEN WORKBOOK. 
    Dim src As Workbook
    Set src = Workbooks("6251 Vivint Rental Report.xlsm")
    'Set src = Workbooks("Vivint-Open.csv").Worksheets("OPEN TICKETS").Range("A1")
    
    Dim valueBookA As String
    valueBookA = src.Worksheets("Data").Cells(1, 2)
    Cells(1, 1).Value = valueBookA
  '******************************************************

  
    'ActiveWorkbook.Save
    
'Below will email the workbook as an attachment
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

'~~> Change path here
    'StrPath = "\\fleet.ad\data\Data1\VMSSHARE\FS\FPSCOEASSO\All Workbooks\6251 Vinvint Rental Report.xlsm" & [D33]

    On Error Resume Next
    With OutMail
        .BodyFormat = olFormatRichText
        .To = valueBookA  '****************TRYING TO HAVE THE EMAIL ADRRESS PLACED HERE******
        .CC = [D34]
        .Subject = [D35] & [D19] & " " & [K19]
        .HTMLBody = [D36] & [D19]
        .Attachments.Add ActiveWorkbook.FullName
        'You can add other files also like this
        '.Attachments.Add ("C:\Users\RPlohocky\Desktop\Macro Projects\GE Idle List.xlsm")
        

        .Display   'or use .Display
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
    
    ActiveWorkbook.Save
    'ActiveWorkbook.Close
    
    End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
You need to change the line

Code:
.BodyFormat = olFormatRichText

to

Code:
.BodyFormat = 3

Something to do with the late binding of Outlook.
 
Upvote 0

Forum statistics

Threads
1,215,025
Messages
6,122,734
Members
449,094
Latest member
dsharae57

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