在特定页面上使用VBA在Google Chrome中打开Excel中的PDF [英] Open a PDF from Excel with VBA in Google Chrome on a specific page
问题描述
我正在Excel中创建一个宏,该宏应在带有chrome的指定页面上打开PDF文档.
I am creating a macro in Excel that should open a PDF document on a specified page with chrome.
通常,开头部分起作用.我的问题是,当我将页码(例如#page = 15)添加到url时,shell对#"编码进行编码.符号插入%23",Chrome无法正确解释(找不到文件).
Generally, the opening part works. My problem is that when I add the page number (e.g. #page=15) to the url, the shell encodes the "#" symbol into "%23", which Chrome is not able to interpret correctly (file not found).
这是我的代码
'The path to the file, replaces spaces with the encoding "%20"
Path = Replace((filePath& "#Page=" & iPageNum), " ", "%20")
Dim wshShell, chromePath As String, shellPath As String
Set wshShell = CreateObject("WScript.Shell")
chromePath = wshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe\")
shellPath = CStr(chromePath) & " -url " & Path
If Not chromePath = "" Then
'how I first tried it:
Shell (shellPath)
'for testing purposes, led to the same result though:
Shell ("""C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"" ""C:\Users\t.weinmuellner\Desktop\Evon\PDF Opening\PDFDocument.pdf#page=17""")
End If
使用Chrome浏览器有其他方法吗?我还没有发现可以动态读取安装路径的任何内容.
Is there a different way to do this with Chrome? I haven't found anything that reads the installation path dynamically.
推荐答案
如果要从本地硬盘加载文件,只需指定协议 file:///
.然后,#
不会转换为%23
.
You just need to specify the protocol file:///
if you want to load files from the local hard disk. Then #
gets not translated into %23
.
Shell ("""C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"" ""file:///C:\Users\t.weinmuellner\Desktop\Evon\PDF Opening\PDFDocument.pdf#page=17""")
这篇关于在特定页面上使用VBA在Google Chrome中打开Excel中的PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!