Skip to main content

How to open specific Excel file from Outlook?

Author: Xiaoyang Last Modified: 2018-09-19

If you want to use a specific Excel file frequently when working on Outlook, so you need to open this file now and then. Is there any quick and easy way for you to open a specified workbook file from Outlook? This article, I will talk about how to solve it.

Open a specific Excel file from Outlook with VBA code


Open a specific Excel file from Outlook with VBA code

You can use the following VBA code to open a default workbook file as you need, please do as this:

1. In Outlook, hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

2. Then, click Insert > Module, and paste the following code in the Module Window.

VBA code: Open a specific Excel file from Outlook:

Public Sub OpenSpecificExcelWorkbook()
    Dim xExcelFile As String
    Dim xExcelApp As Excel.Application
    Dim xWb As Excel.Workbook
    Dim xWs As Excel.Worksheet
   Dim xExcelRange As Excel.Range
    xExcelFile = "C:\Users\DT168\Desktop\split document\kto-data.xlsx"
    Set xExcelApp = CreateObject("Excel.Application")
    Set xWb = xExcelApp.Workbooks.Open(xExcelFile)
    Set xWs = xWb.Sheets(1)
    xWs.Activate
    Set xExcelRange = xWs.Range("A1")
    xExcelRange.Activate
    xExcelApp.Visible = True
End Sub

Note: In the above code, you should change the Excel file path: C:\Users\DT168\Desktop\split document\kto-data.xlsx to your own.

3. And then, still in the Microsoft Visual Basic for Applications window, click Tools > References to go to the References-Project1 dialog box, and check Microsoft Excel Object Library option from the Available References list box, see screenshot:

doc open specific excel 1

4. Then, click OK button to exit the dialog, save and close the code window. Now, you should add this code to the Quick Access Toolbar.

5. In main interface of the Outlook, click Customize Quick Access Toolbar icon, and select More Commands, see screenshot:

doc open specific excel 2

6. In the Outlook Options dialog box:

  • (1.) Select Macros from the Choose commands from drop down list;
  • (2.) And then choose the VBA code name which you have inserted just now;
  • (3.) Click Add button to add the code into the Customize Quick Access Toolbar list box.

doc open specific excel 3

7. And then a macro icon is displayed into the Quick Access Toolbar as following screenshot shown. From now on, when you click this button, your specified Excel file will be opened at once.

doc open specific excel 4


Best Office Productivity Tools

Breaking News: Kutools for Outlook Launches Free Version!

Experience the all-new Kutools for Outlook FREE version with 70+ incredible features, yours to use FOREVER! Click to download now!

🤖 Kutools AI : Instant pro emails with AI magic--one-click to genius replies, perfect tone, multilingual mastery. Transform emailing effortlessly! ...

📧 Email Automation: Auto Reply (Available for POP and IMAP)  /  Schedule Send Emails  /  Auto CC/BCC by Rules When Sending Email  /  Auto Forward (Advanced Rules)   /  Auto Add Greeting   /  Automatically Split Multi-Recipient Emails into Individual Messages ...

📨 Email Management: Recall Emails  /  Block Scam Emails by Subjects and Others  /  Delete Duplicate Emails  /  Advanced Search  /  Consolidate Folders ...

📁 Attachments ProBatch Save  /  Batch Detach  /  Batch Compress  /  Auto Save   /  Auto Detach  /  Auto Compress ...

🌟 Interface Magic: 😊More Pretty and Cool Emojis   /  Remind you when important emails come  /  Minimize Outlook Instead of Closing ...

👍 One-click Wonders: Reply All with Incoming Attachments  /   Anti-Phishing Emails  /  ðŸ•˜Show Sender's Time Zone ...

👩🏼‍🤝‍👩🏻 Contacts & Calendar: Batch Add Contacts From Selected Emails  /  Split a Contact Group to Individual Groups  /  Remove Birthday Reminders ...

Instantly unlock Kutools for Outlook with a single click—permanently free. Don't wait, download now and boost your efficiency!

kutools for outlook features1 kutools for outlook features2
 

 

 

Comments (6)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
7行目のファイルのフルパスを修正して使っていますが、読み取り専用で開いてしまい、データを修正した後上書き保存ができませんでした。

ネットワークフォルダにあるエクセルの場合は、読み取り専用で開いてしまうのでしょうか?
Windowsのプレビューウインドウも含めて、Excelアプリケーションは一切開いていない状態でも同様に読み取り専用で開いてしまいます。
何か対処法があれば教えていただければ幸いです。

ちなみに、Outlook、Excelともに2019環境です。
This comment was minimized by the moderator on the site
Hello,
The code works well in my Outlook, and the Excel file opens normally, not open with read only mode.

You can insert your Excel file here if you don't mind, so that I can check the code.

Thank you!
This comment was minimized by the moderator on the site
Outlook rejects the code immediately with an error. "Compile Error. User defined type not defined." And it zeroes in on "Dim xExcelApp As Excel.Application" as the problem. I literally just copied and pasted it as is into the editor and tried to run it and it fails out immediately.
This comment was minimized by the moderator on the site
Did you enable the microsoft excel library first?
This comment was minimized by the moderator on the site
This works pretty well!

Could you help me with the line of code in addition to it on how to close the workbook without saving changes.
This comment was minimized by the moderator on the site
Or you can run .bat file:


.bat:
@echo off
"C:\Program Files (x86)\Microsoft Office\Office12\EXCEL.EXE" "D:\your_file.xlsx"

and VBA:
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "D:\your_BAT.bat" & Chr(34), 0
Set WshShell = Nothing



https://www.winhelponline.com/blog/run-bat-files-invisibly-without-displaying-command-prompt/
There are no comments posted here yet
Leave your comments
Posting as Guest
Rate this post:
0   Characters
Suggested Locations