我们如何使用Excel VBA将一个文件从远程桌面复制到本地计算机 [英] How can we copy a one file from Remote desktop to local machine using Excel VBA

查看:128
本文介绍了我们如何使用Excel VBA将一个文件从远程桌面复制到本地计算机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Excel VBA将文件从远程桌面复制到本地计算机?

How would I copy a file from Remote desktop to a local machine using Excel VBA?

推荐答案

是的,您可以在VBA中的不同计算机/服务器之间复制文件.您没有指定太多,所以这里是从本地计算机到远程计算机的应对示例.只需更改复制(或移动)的参数即可.

Yes, you can copy files between different computers/servers in VBA. You didn't specify much so here is an example of coping from the local machine to a remote machine. Just change the parameters for the copy (or move) for the reverse.

在我的示例中,我正在访问远程计算机上的管理员共享"Z $".您可以指定任何共享名称.

In my example I'm accessing the admin share 'Z$' on the remote machine. You can specify any share name.

我在Excel 2013中对此进行了测试.

I tested this in 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

这篇关于我们如何使用Excel VBA将一个文件从远程桌面复制到本地计算机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆