是否可以通过 vba 以编程方式将默认 pdf 查看器更改为已安装的 pdf adobe reader dc?有例子吗?
提前致谢。
答案 0 :(得分:0)
尝试使用 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
答案 1 :(得分:0)
您可以使用 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