跳到主要内容

如何从Outlook打开特定的Excel文件?

如果要在Outlook上工作时经常使用特定的Excel文件,则需要不时打开此文件。 是否有任何快速简便的方法可让您从Outlook打开指定的工作簿文件? 本文,我将讨论如何解决它。

使用VBA代码从Outlook中打开特定的Excel文件


使用VBA代码从Outlook中打开特定的Excel文件

您可以根据需要使用以下VBA代码打开默认工作簿文件,请执行以下操作:

1。 在Outlook中,按住 ALT + F11 键打开 Microsoft Visual Basic应用程序 窗口。

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应用程序 窗口中,单击 工具 > 参考资料参考-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