How to open Excel file saved in Outlook folder?

Antonis

New Member
OS Version(s)
  1. Windows
Outlook version
Outlook 365 64 bit
Email Account
Exchange Server
Operating system::    Windows
Outlook version:     new Outlook
Email type or host:    Exchange

Hello,

I'm writing a VBA macro in Excel where I need to open an Excel file saved in an Outlook folder, make some modification and then save it.
Here's the last part of my code:

...
Set myFolder = myFolder.Folders("XXX XXX")

Dim myItem As Object
Set myItem = myFolder.Items("YYYYY.xlsx")

Could you please help?

Thank you.
 
You need to 'find' the file, unless you select it first, then you can use the selection.

I did not test this (yet) so it might have some errors - and it assumes the file is in the folder, not as an attachment on a message.

If you have the exact name and there is no other match, this should work instead of getting the count and looping.
Set myItem = ResItems.Item(1)



Code:
    Set olApp = Outlook.Application
    Set olNs = olApp.GetNamespace("MAPI")

Set olFolder = olNs.GetDefaultFolder(olFolderInbox)
Set myFolder = olFolder.Folders("subfoldername")
    Set olItems = myfolder.items
   
    exFile = "filename.xlxs"
 
    sFilter = "[Subject] = " & exFile
   
    Set ResItems = olItems.Restrict(sFilter)
     iNumRestricted = 0
   fCount = ResItems.Count
 
   'Loop through the items in the collection.
   For counter = fCount To 1 Step -1
 
Set myItem  = ResItems.Item(counter)
   iNumRestricted = iNumRestricted + 1

' do whatever
Debug.Print myItem.Subject
 
You need to 'find' the file, unless you select it first, then you can use the selection.

I did not test this (yet) so it might have some errors - and it assumes the file is in the folder, not as an attachment on a message.

If you have the exact name and there is no other match, this should work instead of getting the count and looping.
Set myItem = ResItems.Item(1)



Code:
    Set olApp = Outlook.Application
    Set olNs = olApp.GetNamespace("MAPI")

Set olFolder = olNs.GetDefaultFolder(olFolderInbox)
Set myFolder = olFolder.Folders("subfoldername")
    Set olItems = myfolder.items
  
    exFile = "filename.xlxs"
 
    sFilter = "[Subject] = " & exFile
  
    Set ResItems = olItems.Restrict(sFilter)
     iNumRestricted = 0
   fCount = ResItems.Count
 
   'Loop through the items in the collection.
   For counter = fCount To 1 Step -1
 
Set myItem  = ResItems.Item(counter)
   iNumRestricted = iNumRestricted + 1

' do whatever
Debug.Print myItem.Subject

Hi Diane,

Thanks a lot for your reply.
I have found the file and selected it but I don't know how to open it in Excel (what method/function to use) since it's an item.
Do you know how to do it?

Thank you.
 
Testing it now -
if I know the position of the file, I can get the file:
Set myItem = olItems(3)

But the filter is not finding it or errors.

Oh, and the filter needs apostrophes -
sFilter = "[Subject] = '" & exFile & "'"
 
Similar threads
Thread starter Title Forum Replies Date
P Excel 2010 can't open .xlsx files Using Outlook 1
D Outlook VBA to open Excel attachment and send recipient's email address to a workbook cell? Using Outlook 4
B What is the best way to use Outlook address book to select customer and then open Excel Outlook VBA and Custom Forms 22
C How To Open Outlook Attachment in Excel, Modify some Data, then Re-Save It Using Outlook 3
C Open/Close Outlook - Via Excel VBA Using Outlook 2
T Word attached files open Word. Excel files open Picture Manager!! Using Outlook 2
W Using Excel UserForm from Open Workbook in Outlook VBA Outlook VBA and Custom Forms 5
ughlook Open multiple contacts in NEW Outlook? Using Outlook 3
K Outlook font corrupted in some point sizes, resets on close/open Using Outlook 2
T Cannot open .pst file Using Outlook 2
H Finding text in open email Outlook VBA and Custom Forms 12
chummy Open multiple Hyperlinks to download files Outlook VBA and Custom Forms 3
G Get current open draft message body from VBA Outlook VBA and Custom Forms 1
Rupert Dragwater How to get Outlook 365 to open from websites Using Outlook 5
Witzker Outlook 2019 Edit contact from email does not open the user defined contactform Using Outlook 3
S Leaving ActiveExplorer open for editing after Sub is done Outlook VBA and Custom Forms 0
Commodore PDF attachments started to open in Edge Using Outlook 0
T Outlook 2021 Cannot open attachments Outlook DeskTop 2021 Using Outlook 0
X Open Hyperlinks in an Outlook Email Message (Help with Diane's solution) Outlook VBA and Custom Forms 3
S HTML Code Embedded in String Within Open Outlook Email Preventing Replace(Application.ActiveInspector.CurrentItem.HTMLBody From Working Outlook VBA and Custom Forms 4
talla Can't open Outlook Item. Using Outlook 0
O Outlook on Android: after sharing / sending a news article, draft remains open. Why? Using Outlook 1
K Embedded photos no longer open with Photos or Photo Viewer Using Outlook 7
Witzker Open Contact missing in Outlook 2019 Using Outlook 2
L Cannot open PST file for first session each day Using Outlook 6
A How to open a specific link automatically with outlook 2016 Outlook VBA and Custom Forms 6
H Upon opening Outlook, make my popmail inbox open instead of outlook.com inbox Using Outlook 1
sahameed82 SharePoint calendar directly open in Outlook Using Outlook 0
N .pst archive from work will not open/import on Microsoft 365 Exchange Server Administration 0
C Outlook 2016/2019 hangs after being open for an extended period Using Outlook 4
M Where is the setting to *turn off* open calendar in a new window? Using Outlook 3
W Automatically open attachments without automatically printing them Using Outlook 0
Y Open and Save Hyperlink Files in multiple emails Outlook VBA and Custom Forms 9
J How to open OST file in Outlook 2019 & 2016 Using Outlook 1
C Can't Open Outlook 365 Using Outlook 0
D after delete mail, open the next one Outlook VBA and Custom Forms 0
N VBA Script to Open highlighted e-mail and Edit Message Outlook VBA and Custom Forms 5
M outlook won't open! Using Outlook 1
N Open & Save VBAProject.Otm using VBA Code Outlook VBA and Custom Forms 1
E Unable to open Outlook 2010 after adding new email account Using Outlook 4
M other user's mailbox won't open, forms disappeared Using Outlook 42
S SendFromAccount - Problem trying to test existing value in open email Outlook VBA and Custom Forms 2
J Open an outlook email by Subject on MS Access linked table with VBA Outlook VBA and Custom Forms 10
D Add Tetxbox at form open Outlook VBA and Custom Forms 1
U Catching ModuleSwitch events after "open in new window" Outlook VBA and Custom Forms 2
Andrew Quirl Open attachment, manipulate without add-on program? Outlook VBA and Custom Forms 5
S Reminder Dialog Open Button Using Outlook 2
A How to open a specific link automatically with outlook Outlook VBA and Custom Forms 13
S Outlook 2010 Cannot Open Attachments Using Outlook 14
N open the hyperlink in Outlook directly instead of browser Using Outlook 1

Similar threads

Back
Top