簡體   English   中英

VBA將Solidworks文件復制到中央文件夾

[英]VBA to copy solidworks files to a central folder

早上好,我的一位同事讓我看一下他的SolidWorks VBA,我對問題所在感到困惑。 基本上,他正在搜索舊的SolidWorks工程圖,以查找與他正在從事的新項目相關的工程圖。 如果找到合適的圖紙,則使用宏來制作該圖紙的副本,將其移動到新項目的文件夾中,關閉舊文件,然后打開新圖紙。 宏如下

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

為他煩惱的那條線是

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

有任何想法嗎? 謝謝

bFailIfExists是否為CopyFile的最后一個參數。

如果此參數為TRUE並且lpNewFileName指定的新文件已經存在,則該函數將失敗。 如果此參數為FALSE並且新文件已經存在,則該函數將覆蓋現有文件並成功執行。

資源

那是可能的。 另外,請檢查DestinationFolder & CurrentOpenFile是否有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM