Sub CATMain() Dim LanguageAsString Language="VBSCRIPT" ' Initialize Dim sTitle As String sTitle = "Select an Excel file" Dim sExtension As String sExtension = ".xls" ' Create the file environment Dim oFso As FileSystem Set oFso = CATIA.FileSystem Dim oFile As File Dim oTextStream As CATIATextStream ' Open the output file Dim iReturnCode As Integer iReturnCode = vbRetry While (iReturnCode = vbRetry) ' Retrieve the path from the user Dim sFilePath As String sFilePath = CATIA.FileSelectionBox(sTitle, sExtension, CatFileSelectionModeSave) If (sFilePath = "") Then iReturnCode = vbCancel Else ' Verify the existence of the output file sFilePath = sFilePath+sExtension Dim iOverwrite As Boolean iOverwrite = False If (oFso.FileExists(sFilePath)) Then ' Ask user if output file exists iReturnCode = Msgbox("The file "+sFilePath+" already exists ! Do you want to overwrite it ?", vbQuestion+vbAbortRetryIgnore, sTitle) If (iReturnCode = vbAbort) Then iReturnCode = vbCancel ElseIf (iReturnCode = vbIgnore) Then iReturnCode = vbOK iOverwrite = True End If else iReturnCode = vbOK End If ' Create the output file If (iReturnCode = vbOK) Then On Error Resume Next Set oFile = oFso.CreateFile(sFilePath, iOverwrite) If (Err.Number <> 0) Then Err.Clear iReturnCode = Msgbox("Cannot Create "+sFilePath+" !", vbExclamation+vbRetryCancel, sTitle) Else ' Open the output file Set oTextStream = oFile.OpenAsTextStream("ForWriting") If (Err.Number <> 0) Then iReturnCode = Msgbox("Cannot open "+sFilePath+" as a text file for writting !", vbExclamation+vbRetryCancel, sTitle) End If End If On Error goto 0 End If End If Wend End Sub