I have written the following VBA code to save my Solidworks files. It also checks if files already exists in the folder and if so - asks through a messagebox if these files need to be overwritten. This is the code:
Main sub()
PathInit = Part.GetPathName 'Determine file location of the assembly
PathCut = Left(PathInit, InStrRev(PathInit, "\")) 'Remove text "Assembly.SLDASS" after the last slash
initName = PathCut + ArrayList(i) + ExtInit 'Name to open the original file
finalName = PathCut & FolderName & "\" & NumPart(initName) & "_" & mldpartcode & " " & ArrayListAdapted & " " & "[REV" & UserParam.getREV(UserParam, CStr(ArrayListNr(i))) & "]" & ExtNew 'New filename
finalNameCut = NumPart(initName) & "_" & mldpartcode & " " & ArrayListAdapted & " " & "[REV" & UserParam.getREV(UserParam, CStr(ArrayListNr(i))) & "]" & ExtNew
For i = LBound(ArrayList) To UBound(ArrayList) 'Run loop x times depending on the amount of selected checkboxes in the userform
'Save the file if it does not exist yet
Dim FileNameOverwrite
Dim IsToBeSaved
IsToBeSaved = True
If Not Dir(finalName, vbDirectory) = vbNullString Then
FileNameOverwrite = MsgBox("Filename " & finalNameCut & " already exists. Do you want to overwrite?", vbQuestion + vbYesNoCancel, "File overwrite")
UserParam.Hide
If FileNameOverwrite = vbNo Then
UserParam.Show
IsToBeSaved = False
'Exit Sub ' Stop the code execution, no more looping
End If
If FileNameOverwrite = vbCancel Then
UserParam.Show
Exit Sub
End If
End If
If IsToBeSaved Then
swModelToExport.Extension.SaveAs3 finalName, 0, 1, Nothing, Nothing, nErrors, nWarnings
End If
'Close all the files
swApp.CloseDoc ArrayList(i) & ".SLDPRT"
'Reopen assembly
Set swModel = swApp.OpenDoc6(PathInit, 1, 0, "", nStatus, nWarnings) 'Open the model
Set swModelActivated = swApp.ActivateDoc3(PathInit, False, swRebuildOnActivation_e.swUserDecision, nErrors) 'Activate the model
Set swModelToExport = swApp.ActiveDoc 'Get the activated model
Next
End Sub
This works pretty good, except for overwriting of multiple files.
Lets say I already saved two files called "Saved1" and "Saved2".
Now, I save the two exact same files again and want the code to ask me if I want to overwrite each file or not with the following pop-up:
If I choose the option "Yes", than the code works fine and a similar messagebox pops up, but for Saved2 this time.
However, if I select the option 'No' for the first file ("Saved1"), then it goes just back to my userform, instead of asking if I want to overwrite Saved2, even if I did not want to overwrite Saved1.
Does anyone know how to adapt the code, so that is asks if I want to overwrite the second file, EVEN THOUGH I do not want to overwrite the first file?
Thank you in advance

Saved1andSaved2defined/allocated/looped?ArrayList,i,finalName,finalNameCut), so it's not very clear exactly how the code is called and in what context.UserParam.Showin your loop before you setIsToBeSaved = False? You're saying that you don't want to go back to the userform when you click no but then you tell your loop to show the form when you click no