【问题标题】:VBA Change default pdf viewerVBA更改默认pdf查看器
【发布时间】:2021-06-09 03:29:17
【问题描述】:

是否可以通过 vba 以编程方式将默认 pdf 查看器更改为已安装的 pdf adobe reader dc?有没有例子?

提前致谢。

【问题讨论】:

    标签: vba pdf ms-word


    【解决方案1】:

    尝试使用 Shell。可以指定应用路径

    Sub Test()
        Dim sPath As String, sFile As String
        sPath = "C:\Program Files (x86)\Adobe\Acrobat 10.0\Acrobat\Acrobat.exe"
        sFile = ThisWorkbook.Path & "\Sample.pdf"
        Shell sPath & " " & sFile
    End Sub
    

    【讨论】:

      【解决方案2】:

      您可以使用 Shell 命令指定可用于打开文件的可执行文件。但是如果要更改默认应用程序,则需要处理 windows 注册表。 Windows 注册表中设置的默认应用程序,您将在注册表位置找到默认应用程序:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion。以下示例代码向您展示了如何通过自动化 windows 脚本主机来创建文件关联:

      Sub AssociateFileTypeWithApp(EXT As String, FileType As String, _
      FileName As String)
      On Error Resume Next
      Dim b As Object
      Set b = CreateObject("wscript.shell")
      With b
      .regwrite "HKCR\" & EXT & "\", FileType
      .regwrite "HKCR\" & FileType & "\", "MY file"
      .regwrite "HKCR\" & FileType & "\DefaultIcon\", FileName
      .regwrite "HKCR\" & FileType & "\shell\open\command\", FileName & " %L"
      .regdelete "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & EXT & "\Application"
      .regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & EXT & "\Application", FileName
      .regdelete "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & EXT & "\OpenWithList\"
      .regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & EXT & "\OpenWithList\a", FileName
      End With
      End Sub
      

      【讨论】:

        猜你喜欢
        • 2019-10-06
        • 2018-03-05
        • 2012-09-12
        • 2019-11-06
        • 1970-01-01
        • 2018-03-20
        • 2018-12-31
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多