使用excel宏移动文件

使用excel宏移动文件,excel,vba,Excel,Vba,我希望我的csv能够运行命令,将文件从主目录位置移动到Windows上的公共目录 我尝试了各种语法,所有前缀都带有=cmd',用于执行命令 =cmd|’move C:\document.docx C:\public\document.docx’! 这应该是将此文件移动到公共目录,该目录可以通过web访问。但是,我无法检索它。我正在运行MacOS,因此无法在本地进行测试。目标框是远程的 CSV是一种功能有限的excel格式(仅用于各种平台或用其他语言编程的应用程序之间的集成) 只能使用“.xls

我希望我的csv能够运行命令,将文件从主目录位置移动到Windows上的公共目录

我尝试了各种语法,所有前缀都带有=cmd',用于执行命令

=cmd|’move C:\document.docx C:\public\document.docx’!

这应该是将此文件移动到公共目录,该目录可以通过web访问。但是,我无法检索它。我正在运行MacOS,因此无法在本地进行测试。目标框是远程的

CSV是一种功能有限的excel格式(仅用于各种平台或用其他语言编程的应用程序之间的集成) 只能使用“.xlsm”或“.xlsb”格式执行此操作

我在另一个线程中发现了此代码

Sub MoveFiles()
Dim sourceFolderPath As String, destinationFolderPath As String
Dim FSO As Object, sourceFolder As Object, file As Object
Dim fileName As String, sourceFilePath As String, destinationFilePath As String
Application.ScreenUpdating = False
sourceFolderPath = "D:\SourceFolder"
destinationFolderPath = "D:\DestinationFolder"
Set FSO = CreateObject("Scripting.FileSystemObject")
Set sourceFolder = FSO.Getfolder(sourceFolderPath)
For Each file In sourceFolder.Files
fileName = file.Name
If InStr(fileName, ".xlsx") Then ' Only xlsx files will be moved
    sourceFilePath = file.Path
    destinationFilePath = destinationFolderPath & "\" & fileName
    FSO.MoveFile Source:=sourceFilePath, Destination:=destinationFilePath
End If ' If InStr(sourceFileName, ".xlsx") Then' Only xlsx files will be moved
Next
'Don't need set file to nothing because it is initialized in for each loop 
'and after this loop is automatically set to Nothing
Set sourceFolder = Nothing
Set FSO = Nothing
End Sub
你可以在这里找到合适的答案
“stackoverflow.com/questions/38456928/将文件从一个文件夹移动到另一个文件夹”

使用
Name…作为
语句

见:


CSV
做不到。它需要启用宏工作簿
.xlsm
文件格式。也许他说的是CSV注入,尽管我不知道这是否在MACI上工作,只是用一个包含类似“=cmd |”/C move filename1 filename2,它确实在windows机器上工作。对于CSV注入,您可以查看。但问题是:你为什么要这样做?
Sub moveFile()
    dim oldname as string, newname as string
    oldname = "C:\document.docx"
    newname = "C:\public\document.docx"

    name oldname as newname
End Sub