跳到主要內容

如何從Outlook打開特定的Excel文件?

如果要在Outlook上工作時經常使用特定的Excel文件,則需要不時打開此文件。 是否有任何快速簡便的方法可讓您從Outlook打開指定的工作簿文件? 本文,我將討論如何解決它。

使用VBA代碼從Outlook中打開特定的Excel文件


使用VBA代碼從Outlook中打開特定的Excel文件

您可以根據需要使用以下VBA代碼打開默認工作簿文件,請執行以下操作:

1。 在Outlook中,按住 ALT + F11 鍵打開 Microsoft Visual Basic for Applications 窗口。

2。 然後,點擊 插入 > 模塊,然後將以下代碼粘貼到 模塊 窗口。

VBA代碼:從Outlook打開特定的Excel文件:

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

備註:在上面的代碼中,您應該更改Excel文件路徑: C:\ Users \ DT168 \ Desktop \ split document \ kto-data.xlsx 給你自己

3。 然後,仍然在 Microsoft Visual Basic for Applications 窗口中,單擊 工具 > 參考參考-Project1 對話框,然後檢查 Microsoft Excel對像庫 選項從 可用參考 列錶框,請參見屏幕截圖:

doc打開特定的excel 1

4。 然後,點擊 OK 按鈕退出對話框,保存並關閉代碼窗口。 現在,您應該將此代碼添加到 快速訪問工具欄.

5。 在Outlook的主界面中,單擊 自定義快速訪問工具欄 圖標,然後選擇 更多命令,請參見屏幕截圖:

doc打開特定的excel 2

6.Outlook選項 對話框:

  • (1.)選擇 來自 從中選擇命令 下拉列表;
  • (2.)然後選擇您剛才插入的VBA代碼名稱;
  • (3.)點擊 加入 按鈕將代碼添加到 自定義快速訪問工具欄 列錶框。

doc打開特定的excel 3

7。 然後,將一個宏圖標顯示到 快速訪問工具欄 如下圖所示。 從現在開始,當您單擊此按鈕時,將立即打開您指定的Excel文件。

doc打開特定的excel 4


最佳辦公生產力工具

Kutools for Outlook - 超過 100 種強大的功能可增強您的 Outlook

🤖 人工智慧郵件助手: 具備人工智慧魔力的即時專業電子郵件——一鍵天才回覆、完美語調、多語言掌握。輕鬆改變電子郵件! ……

📧 電子郵件自動化: 外出(適用於 POP 和 IMAP)  /  安排發送電子郵件  /  發送電子郵件時按規則自動抄送/密件副本  /  自動轉送(進階規則)   /  自動添加問候語   /  自動將多收件者電子郵件拆分為單獨的訊息 ...

📨 電子郵件管理: 輕鬆回憶電子郵件  /  按主題和其他人阻止詐騙電子郵件  /  刪除重複的電子郵件  /  進階搜索  /  合併資料夾 ...

📁 附件專業版批量保存  /  批量分離  /  批量壓縮  /  自動保存   /  自動分離  /  自動壓縮 ...

🌟 介面魔法: 😊更多又漂亮又酷的表情符號   /  使用選項卡式視圖提高 Outlook 工作效率  /  最小化 Outlook 而不是關閉 ...

👍 一鍵奇蹟: 使用傳入附件回覆全部  /   反網路釣魚電子郵件  /  🕘顯示寄件者的時區 ...

👩🏼‍🤝‍👩🏻 通訊錄和行事曆: 從選定的電子郵件中大量新增聯絡人  /  將聯絡人群組拆分為各組  /  刪除生日提醒 ...

超過 100特點 等待您的探索! 按此處了解更多。

閱讀更多       免費下載      購買
 

 

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
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations