简体   繁体   English

如何使用 excel 中的 vba 关闭特定名称 pdf 文档

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

I am operating on excel to control open and close a pdf document by VBA.我正在对 excel 进行操作,以控制 VBA 的 pdf 文档的打开和关闭。 I can open a unique pdf document by using the below code我可以使用以下代码打开一个唯一的 pdf 文档

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

By using code above I can open the named "example.pdf" successfuly.通过使用上面的代码,我可以成功打开名为“example.pdf”的文件。 But when I want to close the unique pdf document I opened I use the shell command但是当我想关闭我打开的唯一 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. 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.

My question is how to close a unique pdf document but do nothing to the other pdf I already opened?我的问题是如何关闭一个独特的 pdf 文档,但对我已经打开的其他 pdf 不做任何事情?

What if you assign the shell command to a variable like this:如果将 shell 命令分配给如下变量会怎样:

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

and then close it like that:然后像这样关闭它:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM