VBA Code to copy Solidworks files to another folder?

UncleBajubjubs

Board Regular
Joined
Jul 11, 2017
Messages
111
Office Version
  1. 2010
My apologies if this is the incorrect place to psot this, the forum says all VBA questions so I believe this counts, anyway:

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

<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">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

EndSub

</code>The line that is bugging for him is
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Call FSO.CopyFile(MyPath, DestinationFolder & CurrentOpenFile,True)</code>Any ideas? Thanks
 
Last edited:

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Code:
Call FSO.CopyFile(MyPath, DestinationFolder & CurrentOpenFile,True)
This statement is a little bothersome to me, also. It looks like a macro call, but it uses the script sysntax for doing the copy,except that there is only a path and not file name for the file to copy. You could try removing the word 'Call' and see what happens. I wouold also try concatenating the file name after "MyPath". Another point is that the DestinationFolder string needs to have a backslash added after 'subfolder' or vbs will think that subfolder is the part of the file name you are trying to add. You will probably need to make sure there is a backslash at the end of the string that 'MyPath' variable holds.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,568
Messages
6,179,595
Members
452,927
Latest member
whitfieldcraig

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top