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

  • What does "bugging for him" ***mean***? Does it throw an error? If so, what is the error? – Comintern Feb 26 '19 at 15:32
  • He said it occasionally gives an error, but can't recall exactly what it is and isn't sure what changes sometimes cause it.. Yes I realize that's not the most helpful, our apologies. – Crebuloboldoaps Feb 26 '19 at 16:00

1 Answers1

0

bFailIfExists if the last parameter of CopyFile.

If this parameter is TRUE and the new file specified by lpNewFileName already exists, the function fails. If this parameter is FALSE and the new file already exists, the function overwrites the existing file and succeeds.

Source

That's a possibility. Also, check if DestinationFolder & CurrentOpenFile is valid.

Amen Jlili
  • 1,884
  • 4
  • 28
  • 51