Copy e-mail body to Excel through Access

mikenelena

Board Regular
Joined
Mar 5, 2018
Messages
139
Office Version
  1. 365
Platform
  1. Windows
I am looking to bring data from an Outlook message into Access using Excel as a "middleman" for ease of referencing the data. In testing I've been able to copy successfully from Outlook to Excel, and import data successfully from Excel into Access. Now I'm just looking to handle the entire process from Access. The actual copying of the e-mail body is where I'm having difficulty. The line of code that worked in Outlook vba is not working in Access vba. I'm thinking I have a problem with a variable dim, or set, but I can't seem to work it out. I can close the open e-mail from Access, so I know the applications are at least talking to one another. If anyone could help me iron this out, I'd be very grateful. Thanks!

VBA Code:
Private Sub cmdNewFromEmail_Click()

Dim strWhere As String

Dim xl As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim filePath As String

Dim objol As Outlook.Application
Dim MyInspector As Outlook.Inspector
Dim objItem As Outlook.MailItem
Dim CurrentMessage As Outlook.MailItem

Set xl = New Excel.Application
Set xlBook = xl.Workbooks.Open(filePath)
Set xlSheet = xlBook.Worksheets(1)

'Set OL = GetObject(, "Outlook.Application")
Set objol = New Outlook.Application
Set MyInspector = Outlook.ActiveInspector
Set objItem = MyInspector.CurrentItem

filePath = "S:\UserName\" & "Excel Test File" & ".xlsx"

xl.Visible = True
'OL.Visible = True


    DoCmd.GoToRecord , , acNewRec
           Me.File_Number = Nz(DMax("File_Number", "ClaimInfo1", strWhere), 0) + 1      'Setting up a new file in Access
           
           Me.Invoice_Number = Me.File_Number & "-01"
           
           DoCmd.RunCommand acCmdSaveRecord
           
 Me.SubformContainer.SourceObject = "Appraisals_Subform2"   'Binds Client Billing tab to Invoicing form when setting up new file 
 Forms!Invoicing_Form.TabCtlEval = 0                        'Sets focus on the appropriate tab.

'-----------------------------------------------------------------------------------------------------------------

    With objItem
    
    'Set CurrentMessage = ActiveInspector.CurrentItem
    Set CurrentMessage = MyInspector.CurrentItem
    
    CurrentMessage.GetInspector().WordEditor.Range.FormattedText.Copy      ' *** This is the line causing the problem. Other things I've tried are commented out.***
    'CurrentMessage.Close olSave
    'CurrentMessage.GetInspector().WordEditor.Range.FormattedText
    'CurrentMessage.Copy
      
    End With
'-----------------------------------------------------------------------------------------------------------------
    With xlSheet
    
        .Range("A1").Select
        .Paste
        
        .Range("F5").Value = "Claim:  "
        .Range("G5").Formula = "=INDEX(B1:B100,MATCH(F5,A1:A100,0))"
     'many similar lines have been removed to keep the code short and readable here.
    End With

Me.Claim_Number = Range("G5")

End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,214,985
Messages
6,122,605
Members
449,089
Latest member
Motoracer88

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