UncleBajubjubs
Board Regular
- Joined
- Jul 11, 2017
- Messages
- 111
- Office Version
- 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
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: