Excel VBA与虚拟机进行交互

时间:2018-12-28 03:59:51

标签: excel vba virtual-machine

我的问题是关于Excel VBA和与虚拟机交互的问题。我的项目的重点是使用我的凭据登录我的雇主网站-打开虚拟机的文件浏览器(到目前为止,这两个步骤都已完成)-然后在虚拟机中单击适当的文件-然后在新打开的文件。我一直在选择虚拟机中的文件。我将在下面粘贴我的代码。我收到的错误是“找不到文件”,我相信这是因为代码正在搜索我PC的文件浏览器而不是虚拟机。任何帮助是极大的赞赏。

Sub login()

Dim ie As SHDocVw.InternetExplorer
Set ie = New InternetExplorerMedium

ie.Visible = True ' show internet explorer when it opens
ie.navigate ("website name") 'navigate to website

Do While ie.readyState <> READYSTATE_COMPLETE ' wait until webpage is loaded

Loop

Dim idoc As MSHTML.HTMLDocument ' define variable as HTML document
Set idoc = ie.document

idoc.all.user.Value = "User Name"
idoc.all.Password.Value = "Password"
idoc.all.btnLogin.Click

Do While ie.readyState <> READYSTATE_COMPLETE ' wait until next screen loads completely
Loop
Application.Wait (Now + TimeValue("0:00:05")) ' this delay prevented an error from occuring
ie.navigate ("website link within employers site")

Do While ie.readyState <> READYSTATE_COMPLETE

Loop

idoc.getElementById("").Click 'clicking to open the virtual machine file explorer

Application.Wait (Now + TimeValue("0:00:30"))

Shell "'C:\Folder\Folder\Folder\File.xlsx", vbNormalFocus

1 个答案:

答案 0 :(得分:0)

这不完全是您的情况,但我认为这可能有助于解释如何在远程桌面/服务器连接等上正确定位文件。

How can we copy a one file from Remote desktop to local machine using Excel VBA