VBA在Firefox中打开URL并在本地保存网站

问题描述 投票:0回答:2

编码器,

我在VBA中为excel创建了一个代码,用于在Firefox中打开一个特定的网站(见下文)。我需要在FF而不是在资源管理器中打开它因为某些原因我的公司的服务器只显示一个长的XML代码,如果在IE中打开它不会显示(不要问我为什么)。

我有一个在Excel中开发的应用程序,我使用此代码从服务器加载MOZILLA中的XML文件:

'Determine the Path to FF executable
 Set WSHShell = CreateObject("WScript.Shell")
 sFFExe = WSHShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Firefox.EXE\")
 'Open the URL
  Shell """" & sFFExe & """" & " -new-tab """ & sURL & "", vbHide

这段代码完美无缺。是整个URL的变量sURL部分。然后我手动将网站保存为XML文件。

我想知道我是否可以自动执行此保存文件步骤并在后台运行所有步骤。我在我的计算机上有XML文件,我可以继续使用我的其余宏从XML中提取数据。

有任何想法吗?

非常感谢。

xml vba url save mozilla
2个回答
0
投票

我找到的解决方案是以下代码:用于打开mozilla中的url:

'Determine the Path to FF executable
Set WSHShell = CreateObject("WScript.Shell")
sFFExe = WSHShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Firefox.EXE\")
'Open the URL
Shell """" & sFFExe & """" & " -new-tab """ & sURL & "", vbHide

其中sURL是您的网站www.whatever.com现在要保存网站(没有关键时间之间没有时间)

Sub save_XML_file()
Application.Wait Now + TimeValue("00:00:05")
SendKeys "^s", True
Application.Wait Now + TimeValue("00:00:05")
'here it is not possible to send the key strolkes of a variable. therefore always saving the file ascurrent.txt and afterwads in a third routine copy and renaming the file.

SendKeys "Current.XML", True
Application.Wait Now + TimeValue("00:00:04")
SendKeys "{TAB}", True
Application.Wait Now + TimeValue("00:00:04")
SendKeys "{TAB}", True
Application.Wait Now + TimeValue("00:00:04")
SendKeys "{TAB}", True
Application.Wait Now + TimeValue("00:00:04")
SendKeys "{ENTER}", True
Application.Wait Now + TimeValue("00:00:04")

结束子


0
投票

谢谢,等待时间解决了问题。对于变量文件名的问题,我没有尝试插入变量。作为一种解决方法,我在excel表中定义了相应的文件名,每次都将它们复制到剪贴板。打开'文件保存'窗口后,我只需发送'Ctrl'+ v:

    Selection.Copy 'copies filename from actual selected cell into clipboard
    ...
    Application.SendKeys ("^s")
    Application.Wait (Now + TimeValue("0:00:01"))
    Application.SendKeys "^v", True
© www.soinside.com 2019 - 2024. All rights reserved.