0

Good morning, a coworker of mine asked me to take a look at his VBA for Solidworks and I'm stumped as to what the issue is. Basically, he is searching through old solidworks drawings to find ones relevant to a new project he is working on. If he finds one that is relevant, he uses a macro to make a copy of that drawing, move it to the folder for the new project, close the old file, and open the new one. The macro is as following

Sub Move_Copy()

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set FSO = VBA.CreateObject("Scripting.FileSystemObject")

'Where the Copy Files are going
DestinationFolder = "\\SERVER\FOLDER\subfolder"

'Gets full path name of current file that is open
MyPath = swModel.GetPathName

'Gets File Name with extension
CurrentOpenFile = Mid(swModel.GetPathName, InStrRev(swModel.GetPathName, "\") + 1)
'This copies the file and moves it
Call FSO.CopyFile(MyPath, DestinationFolder & CurrentOpenFile, True)

'This Closes the Current Document
swApp.QuitDoc CurrentOpenFile

'This opens the moved file
swApp.OpenDoc6 DestinationFolder & CurrentOpenFile, swDocDRAWING, swOpenDocOptions_Silent, "", ERRORS, WARNINGS

End Sub

The line that is bugging for him is

Call FSO.CopyFile(MyPath, DestinationFolder & CurrentOpenFile, True)

Any ideas? Thanks

4

1 回答 1

0

bFailIfExists如果 的最后一个参数CopyFile

如果此参数为 TRUE 并且 lpNewFileName 指定的新文件已经存在,则函数失败。如果此参数为 FALSE 且新文件已存在,则该函数将覆盖现有文件并成功。

资源

这是一种可能。另外,检查是否DestinationFolder & CurrentOpenFile有效。

于 2019-03-08T03:18:21.760 回答