VBA to open excel attachment in current Outlook email

Mylarbi

New Member
Joined
Feb 9, 2020
Messages
48
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi helpers,
Currently I have a macro that works okay on Excel file attachments I manually open them in Outlook.
I want to add a new starting point to this macro such that
1. it opens the attached Excel file in the current Outlook email
2. it continues the remaining steps which work okay as mentioned.
Thanks
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Did you ever send someone an email with an attachment only to realize that after you hit the send button you had forgotten to add the attachment. That is the feeling I get when I read this post...
 
Upvote 0
Hi @igold,
To begin with, I have opened an Outlook email with an attached Excel file (not opened).
Then I open Excel workbook (say Workbook M) with the macro.
On execution, I need the macro to automatically go to Outlook and open the email attachment of the current email. This will become a second workbook (say ThisWorkbook).
 
Upvote 0
Currently I have a macro that works okay on Excel file attachments I manually open them in Outlook.
I want to add a new starting point to this macro
I don't see a macro....
 
Upvote 0
Okay the macro is
VBA Code:
Sub PVTOPTS()
    Dim wb1, wb2 As Workbook
    Dim wsORIG, wsPVTS As Worksheet
' Settings
    Set wb1 = ActiveWorkbook
    Set wb2 = ThisWorkbook
    Set wsORIG = wb1.Worksheets("DATA")
    Set wsPVTS = wb2.Worksheets("PVTS")
' Get report
    Application.Calculation = xlCalculationManual
    Application.DisplayAlerts = False
    wsORIG.Cells.UnMerge
' New: delete top deck
    wsORIG.Range("F1:F40000").Select
    Selection.SpecialCells(xlCellTypeBlanks).EntireRow.Select
    Selection.Delete
    wsORIG.Range("A2").CurrentRegion.Offset(1) _
    .Resize(Selection.CurrentRegion.Rows.Count - 2).Copy wb2.Sheets("DATA").Range("B3")
'
    Application.CutCopyMode = False
    Application.ScreenUpdating = False
    Application.DisplayAlerts = True
' Refresh all
    wb2.Sheets("DATA").Calculate
    wb2.RefreshAll
 
Upvote 0
Have you tried searching this forum for an answer... Perhaps there is something here...

 
Upvote 0
Also, as a heads up, in your code in Post #5. Your variable declaration of this:
VBA Code:
Dim wb1, wb2 As Workbook
Dim wsORIG, wsPVTS As Worksheet

is the same as declaring them like this:
VBA Code:
Dim wb1 As Variant
Dim wb2 As Workbook
Dim wsORIG As Variant
Dim wsPVTS As Worksheet

it should read like this:
VBA Code:
Dim wb1 As Workbook, wb2 As Workbook
Dim wsORIG As Worksheet, wsPVTS As Worksheet

Your code may work as you want, but that does not negate the fact the variables are not declared correctly.
 
Upvote 0
Have you tried searching this forum for an answer... Perhaps there is something here...

Yes I have searched but have not found one that meets my need. Some I found talk of saving the file, others execute the macro at the time the email is received. In my case, multiple variants of the same report type are received at midnight. So it will be impracticable to run all at the same time. That is why I want to activate the required email first before running the macro.
 
Upvote 0
it should read like this:
VBA Code:
Dim wb1 As Workbook, wb2 As Workbook
Dim wsORIG As Worksheet, wsPVTS As Worksheet

Your code may work as you want, but that does not negate the fact the variables are not declared correctly.
Thanks for the correction. I'm a novice in vba.
 
Upvote 0
Meanwhile, @igold, my question has not been answered nor attempted. I thought you asked for the code I have in order to help?
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,947
Members
449,095
Latest member
nmaske

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