Hello community.
I'm in my early stages on SW macros.
I want to make a macro that fetches the name of the file (without the extension) and registers this string in a personal property.
I'm encountering pbs about splitting the extension of the file name I managed to recover.
Below is the code I wrote. What am I doing wrong because I really don't understand...
Dim swApp As Object
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Dim swBodies As Variant
Dim swBody As SldWorks.Body2
Set Part = swModel
Dim b As String
Dim name
b = swModel.GetTitle
Debug.Print b
name = Split(b, ".", -1)
Debug.Print name
End Sub
Thank you in advance
pl
3
The line must be replaced:
name = Split(b, ".", -1)
By:
Name = Left(b, (InStrRev(b, ".", -1, vbTextCompare) - 1))
Because Split cannot be used like that.
Oops the message received is:
Runtime Error 13
Type incompatibility
1 Like
pl
5
Yes, I tested and saw.
For your information, it is necessary to point out which line is in error too:)
With my previous message it works now.
Thank you very much, but what does this line of code mean???
1 Like
pl
7
For split, see here:
http://silkyroad.developpez.com/VBA/ManipulerChainesCaracteres/#LI-I
To left see here:
http://silkyroad.developpez.com/VBA/ManipulerChainesCaracteres/#LI-B
For instrrev, see here (the difference with instr is that it starts at the end of the string):
http://silkyroad.developpez.com/VBA/ManipulerChainesCaracteres/#LI-E
Otherwise, for functions on strings, see also:
http://boisgontierjacques.free.fr/pages_site/chainesvba.htm