I have a Macro that saves the Products/Parts as their in session part number.
It works great except if I have two products open it switches windows and saves both of them.
How do I modify this Macro to only work on the current open product and keep it from switching to the next open document?
It works great except if I have two products open it switches windows and saves both of them.
How do I modify this Macro to only work on the current open product and keep it from switching to the next open document?
Code:
Sub CATMain()
Dim noSymPartName As String
Dim noSymProductName As String
Dim newCharacter As String
newCharacter = "_"
CATIA.DisplayFileAlerts = False
Set oDocs = CATIA.Documents
docPath = oDocs.Item(1).Path
changePath = MsgBox("Current save location is: " & docPath & " Would you like to change file path?", vbYesNo)
If changePath = vbYes Then
Const WINDOW_HANDLE = 0
Const NO_OPTIONS = &H0001
'Const File_Path = "\\GTFS1\Share\Data\"
Const File_Path = 17
Set objShell = CreateObject("Shell.Application")
'Set objFolder = objShell.BrowseForFolder _
' (WINDOW_HANDLE, "Select a folder:", NO_OPTIONS, " \\GTFS1\Share\Data\")
Set objFolder = objShell.BrowseForFolder _
(WINDOW_HANDLE, "Select a folder:", NO_OPTIONS, File_Path)
Set objFolderItem = objFolder.Self
'objPath = objFolderItem.Path
docPath = objFolderItem.Path
MsgBox docPath,,"Save Location"
'Set objFolderItem = CreateObject("Scripting.FileSystemObject")
'docPath = InputBox("Enter new file path", "File path")
End If
CATIA.RefreshDisplay = False
For x = 1 To oDocs.Count
If TypeName(oDocs.Item(x)) = "ProductDocument" Then
Set oDoc1 = oDocs.Item(x)
Set oProduct1 = oDoc1.Product
noSymProductName = oProduct1.PartNumber 'get the current PartNumber
noSymProductName = Replace(noSymProductName,".","")
noSymProductName = Replace(noSymProductName,",","")
noSymProductName = Replace(noSymProductName,"(","")
noSymProductName = Replace(noSymProductName,")","")
noSymProductName = Replace(noSymProductName,"/","")
noSymProductName = Replace(noSymProductName,"\","")
noSymProductName = Replace(noSymProductName,"#","")
noSymProductName = Replace(noSymProductName,"$","")
noSymProductName = Replace(noSymProductName,"%","")
noSymProductName = Replace(noSymProductName,"*","")
oDoc1.SaveAs docPath & "\" & noSymProductName & ".CATProduct"
End If
Next 'x
For v = 1 To oDocs.Count
If TypeName(oDocs.Item(v)) = "PartDocument" Then
Set oDoc2 = oDocs.Item(v)
Set oPart1 = oDoc2.Product
noSymPartName = oPart1.PartNumber 'get the current PartNumber
noSymPartName = Replace(noSymPartName,".","")
noSymPartName = Replace(noSymPartName,",","")
noSymPartName = Replace(noSymPartName,"(","")
noSymPartName = Replace(noSymPartName,")","")
noSymPartName = Replace(noSymPartName,"/","")
noSymPartName = Replace(noSymPartName,"\","")
noSymPartName = Replace(noSymPartName,"#","")
noSymPartName = Replace(noSymPartName,"$","")
noSymPartName = Replace(noSymPartName,"%","")
noSymPartName = Replace(noSymPartName,"*","")
oDoc2.SaveAs docPath & "\" & noSymPartName & ".CATPart"
On Error Resume Next
End If
Next 'v
CATIA.RefreshDisplay = True
Msgbox "Save Finished!",,"SAVE FINISH!"
Msgbox "YOU HAVE TO USE SAVE MANAGEMENT NOW!",,"YOU HAVE TO USE SAVE MANAGEMENT NOW!"
End Sub