I'm trying to create a macro that fills in the Number property in the property manager from the file name. Currently I can get it to work if I'm very specific with my filename. Ex) 3409 Bot Det 009 button it will apply 009 to the number property the problem is I have a number range from 1-900 so for the macro to work I have to input a 3 digit number. I can live with that I was just wondering if there is a better way to do this. I would also like to run this will I'm in a assembly currently have to run it will i'm in a part. I am really new to macros so any help would be apreciated. Thanks bellow is my current macro.
Dim swApp As Object
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swCustPropMgr = swModel.Extension.CustomPropertyManager("")
'get needed info from model file name
FileName = swModel.GetTitle
ProjectName = Left(FileName, 4)
Number = Mid(FileName, 14, 3)
Dim a As String
'If LCase(Left(Right(FILENAME, 7), 4)) = ".sldasm" Or LCase(Left(Right(FILENAME, 7), 4)) = ".sldprt" Then
'this if statement is an attempt to check if file extensions are turned on in windows explorer
If LCase(Left(Right(FileName, 7), 4)) = ".sld" Then
'if the file extension is found it is removed
PartTitle = Left(Right(FileName, Len(FileName) - 15), Len(FileName) - 15 - 7)
Else
'no file extension found
PartTitle = Left(Right(FileName, Len(FileName) - 15), Len(FileName) - 15)
End If
'Add Project Name to custom properties and add text
swCustPropMgr.Add2 "Project Name", swCustomInfoText, " "
swCustPropMgr.Set "Project Name", ProjectName
'Add Number to custom properties and add text
swCustPropMgr.Add2 "Number", swCustomInfoText, " "
swCustPropMgr.Set "Number", Number
End Sub
