簡體   English   中英

如何使用 excel 中的 vba 關閉特定名稱 pdf 文檔

[英]How to close a specific name pdf document by using vba in excel

我正在對 excel 進行操作,以控制 VBA 的 pdf 文檔的打開和關閉。 我可以使用以下代碼打開一個唯一的 pdf 文檔

ExeFilepath = "C:\Program Files (x86)\Adobe\Acrobat Reader 2015\Reader\AcroRd32.exe "
Filepath = "C:\Work\example.pdf"
Shell(ExeFilepath & Filepath, vbMaximizedFocus)

通過使用上面的代碼,我可以成功打開名為“example.pdf”的文件。 但是當我想關閉我打開的唯一 pdf 文檔時,我使用 shell 命令

Shell "taskkill /F /IM AcroRd32.exe"

The shell command can close the pdf, but it will close all the pdf document I opened regardless of whether I open it manually or by the VBA code.

我的問題是如何關閉一個獨特的 pdf 文檔,但對我已經打開的其他 pdf 不做任何事情?

如果將 shell 命令分配給如下變量會怎樣:

dim pid as variant
pid = Shell(ExeFilepath & Filepath, vbMaximizedFocus)

然后像這樣關閉它:

call shell("taskkill /F /PID " & Cstr(pid))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM