[英]How can we copy a one file from Remote desktop to local machine using Excel VBA
如何使用Excel VBA將文件從遠程桌面復制到本地計算機?
是的,您可以在VBA中的不同計算機/服務器之間復制文件。 您沒有指定太多,所以這里是從本地計算機到遠程計算機的應對示例。 只需為反向更改副本(或移動)的參數。
在我的示例中,我正在訪問遠程計算機上的管理員共享“ Z $”。 您可以指定任何共享名稱。
我在Excel 2013中對此進行了測試。
Option Explicit 'always declare your vars!
Sub CopyFile()
Dim FSO: Set FSO = CreateObject("Scripting.FileSystemObject")
Dim strFile: strFile = "c:\temp\RemoteCopyTest\mytestfile.txt"
Dim strTargetPath: strTargetPath = "\\Server\Z$\"
'verify the remote folder exists
If FSO.FolderExists(strTargetPath) Then
'verify the source file exists
If FSO.FileExists(strFile) Then
'use FSO.MoveFile <Source>,<Target> if you want to move instead of copy
FSO.CopyFile strFile, strTargetPath
Else
MsgBox "ERROR: Source FIle does not exist or is not accessible."
End If
Else
MsgBox "ERROR: Target Folder does not exist or is not accessible."
End If
End Sub
當您連接到遠程PC \\ Server時,您可以選擇共享資源的方式,即,如果使用遠程桌面連接,則其Options \\ z Local Resources \\ More \\ Drives
您可以選擇本地c驅動器,現在可以在Windows資源管理器中的遠程計算機上使用它。
因此,當您運行Excel VBA時,只需要將文件從“遠程”移動到遠程計算機上列出的本地C驅動器(它可能會給它一個新的驅動器號)
正如DevilsAdvocate所說的..它只是從此處復制1個文件
BTW您可以保存您的遠程連接設置...,以便每次您連接到該PC /服務器時都具有相同的設置
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.