How to Quickly Open a Specific Word Document or Excel Workbook in Outlook via VBA

Perhaps when you compose emails, you may frequently need to refer to specific files which are stored in your local hard disk, like a word document or a excel workbook. So this article will teach you to quickly open specific files from Outlook via VBA.

Are you often required to check or refer to specific files when you deal with your emails in Outlook? For instance, your company has set many rules for the emails which are sent to our clients and the rules are listed in a specific Word document. Therefore, every time you compose such an email sent to clients, you will need to refer to the specific document. In this case, it will be quite convenient if you can directly open the specific file from within Outlook. Fortunately, you can achieve it with Outlook VBA.

Open a Specific Word Document in Outlook

  1. For a start, start your Outlook application.
  2. Then press “Alt + F11” key shortcuts to get access to Outlook VBA editor,
  3. Subsequently, in the popup dialog box, open a module which are not in use or insert a fresh new module by “Insert” > “Module”.Insert a Fresh New Module
  4. After that, you should copy the following VBA codes into the new module.
Public Sub OpenSpecificWordDocument()
    Dim strFile As String
    Dim objWordApp As Word.Application
    Dim objWordDocument As Word.Document
    Dim objWordTable As Word.Table
    Dim objWordRange As Word.Range
 
    'Change the following line to point to your own Word document on your local disk
    strFile = "E:\Email\Email Rules.docx"

    Set objWordApp = CreateObject("Word.Application")
    Set objWordDocument = objWordApp.Documents.Open(strFile)
    objWordDocument.Activate
    Set objWordRange = objWordDocument.Range(0, 0)
    objWordApp.Visible = True
    objWordDocument.ActiveWindow.Visible = True
End Sub

VBA Codes - Open a Specific Word Document in Outlook

  1. Later you can close the VBA editor and add the VBA project to Quick Access Toolbar or ribbon. Here we take Quick Access Toolbar as an example, you can follow the steps shown in the image below:Add The New VBA Project to Quick Access Toolbar
  2. Finally, you can back to main Outlook window. As soon as you click the macro button in Quick Access Toolbar, the specific word document will open, shown as the following screenshot:Quickly Open a Specific Word Document from within Outlook

Open a Specific Excel Workbook in Outlook

If you hope to quickly open a specific Excel workbook from within Outlook, you can use the following VBA codes:

Public Sub OpenSpecificExcelWorkbook()
    Dim strFile As String
    Dim objExcelApp As Excel.Application
    Dim objExcelWorkBook As Excel.Workbook
    Dim objExcelWorkSheet As Excel.Worksheet
    Dim objExcelRange As Excel.Range

    'Change the following line to point to your own Word document on your local disk
    strFile = "E:\Email\Email Statistics.xlsx"

    Set objExcelApp = CreateObject("Excel.Application")
    Set objExcelWorkBook = objExcelApp.Workbooks.Open(strFile)
    Set objExcelWorkSheet = objExcelWorkBook.Sheets(1)
    objExcelWorkSheet.Activate
    Set objExcelRange = objExcelWorkSheet.Range("A1")
    objExcelRange.Activate
    objExcelApp.Visible = True
End Sub

VBA Codes - Open a Specific Excel Workbook in Outlook

Next, you can add the new macro to Quick Access Toolbar as usual. When you hit the corresponding button, the specific Excel workbook will display.Quickly Open a Specific Excel Workbook from within Outlook

Never Delay to Resolve Outlook Errors

Since Outlook is susceptible to errors, you must have come across various issues in it. Some of them may be so small and fatal. Hence, sometimes, even though you suffer them, perhaps your Outlook can still work as usual. But you’d better figure out them clearly. Otherwise, accumulating unsolved Outlook issues will result in severe damage on your Outlook data. At that point, if you wish to fix Outlook, you have to resort to a reliable and reputable tool, like DataNumen Outlook Repair.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including fix mdf and outlook repair software products. For more information visit www.datanumen.com

One response to “How to Quickly Open a Specific Word Document or Excel Workbook in Outlook via VBA”

Leave a Reply

Your email address will not be published. Required fields are marked *