ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
RYRaymond Yau09/05/2017

Hi,

This isn't really SW related, but rather a VBA question. I have some code which tests a number of conditions using several Elseif statements, and it defaults to an Else statement if none of the pre-existing conditions match. The intention of the Else statement is to create a text file and then add the file name of the Solidworks File that the macro is running on using Writeline.

Currently, the existing code is programmed in a way that everytime the macro runs, it overwrites the text file that already exists. Instead I would want to have it add to an existing text file without overwriting the file names that already existing within the file.

...

Else

Dim fso As Object

Set fso = CreateObject("Scripting.FileSystemObject")

Dim oFile As Object

Set oFile = fso.CreateTextFile("C:\Users\Anon\Desktop\test.txt") 'Tried booleans, can't seem to get this to work.

oFile.WriteLine "File name - " & swModel.GetTitle

oFile.Close

Set fso = Nothing

Set oFile = Nothing

End If

Thoughts?