使用FollowHyperlink打开已打开的PDF后,将其关闭 [英] Close an opened PDF after opening it using FollowHyperlink

查看:171
本文介绍了使用FollowHyperlink打开已打开的PDF后,将其关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用FollowHyperlink方法打开pdf文件,如下所示:

I am opening a pdf file using the FollowHyperlink method, shown here:

Sub Sample()
    ActiveWorkbook.FollowHyperlink "C:\MyFile.pdf"
End Sub

在此线程中找到的.

我的问题是,如何关闭pdf?

My question is, how do I close the pdf?

推荐答案

这是我使用的两个选项.

Here are two options i use.

选项1:此选项可用来杀死所有不可见的打开的互联网浏览器(又名我弄乱了).可能有一种方法可以通过这种方式将文件选出来,但是我不完全确定没有@Jeeped提到的API调用是可能的.我将列出第二个API调用.

Option1: This option I use it to kill all open internet browsers when they are not visible(aka I messed up). There could be a method to single the file out this way but i am not entirely sure it is possible without an API call as @Jeeped mentioned. I will list the API Call second.

要找出您正在运行的Adobe类型.打开Windows任务管理器>进程,然后找到描述为Adobe Reader的.exe.

To find out which Adobe type you are running. Open Windows Task Manager > Processes and find the .exe with the description Adobe Reader.

Sub Kill_All_PDFs()

   '***ErrorHandler***
   On Error Resume Next

   '***Define Variables***
    Dim objectWMI As Object
    Dim objectProcess As Object
    Dim objectProcesses As Object

    '***Set Objects***
    Set objectWMI = GetObject("winmgmts://.")
    Set objectProcesses = objectWMI.ExecQuery( _
        "SELECT * FROM Win32_Process WHERE Name = 'AcroRd32.exe'") '< Change if you need be

    '***Terminate all Open PDFs***
    For Each objectProcess In objectProcesses
        Call objectProcess.Terminate
    Next

    '***Clean Up***
    Set objectProcesses = Nothing
    Set objectWMI = Nothing
End Sub

Option2 API调用方法:

Option2 API Call Method:

在这里您将可以按标题查找PDF文件.我修改了代码以找到Adobe,但是如果您想进一步阅读它的工作原理,请在下面列出源代码.只需添加显示在PDF文件顶部的标题即可.

Here you will be able to find your PDF file by title. I modified the code to find Adobe but the source is listed below if you would like further reading on how it works. Just add the title as it appears at the top of your PDF file.

来源: http://support.microsoft.com/kb/168204

 Private Declare Function FindWindow _
   Lib "user32" Alias "FindWindowA" _
   (ByVal lpClassName As String, _
   ByVal lpWindowName As String) _
   As Long

   Private Declare Function SendMessage _
   Lib "user32" Alias "SendMessageA" _
   (ByVal hwnd As Long, _
   ByVal wMsg As Long, _
   ByVal wParam As Long, _
   lParam As Long) _
   As Long

  Private Sub Close_AdobeReader()
     Dim lpClassName As String
     Dim lpCaption As String
     Dim Handle As Long

     Const NILL = 0&
     Const WM_SYSCOMMAND = &H112
     Const SC_CLOSE = &HF060&

     lpClassName = "AcrobatSDIWindow"
     lpCaption = "e.g.name - Adobe Reader"  '< add Title Here 

  '* Determine the handle to the Calculator window.
     Handle = FindWindow(lpClassName$, lpCaption$)

  '* Post a message to Calc to end its existence.
     Handle = SendMessage(Handle, WM_SYSCOMMAND, SC_CLOSE, NILL)

  End Sub

希望这对您有所帮助!

这篇关于使用FollowHyperlink打开已打开的PDF后,将其关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆