Im trying to generate an Excel BOM data base without using CATIA. For this porpouse I did an Excel subroutine that reads a CATPart file as a txt file. This way I can manage to get the parameters inside the CATPart file using a simple InStr function.
The problem starts when I try to get the Part Number string (CATIA native, not a created parameter). When I open a CATPart as a txt file I can see that the Part Number is allways on the side of a string "ASMPRODUCT".
It's a quite simple code. But when I try to get the string "ASMPRODUCT" using the InStr function, it does NOT work. AND THE WORD IS THERE WHEN YOU OPEN THE TXT FILE!! I've checked using InStrRev also but I don't have a result either.
Did someone already battled with this problem? Is there a solution?
Dim fsDataFile As Object
Dim sText As Object
Dim sPath As String
Dim line As String
Set fsDataFile = CreateObject("Scripting.FileSystemObject")
line_n = 0
'The fully qualified path to your lookup file
sPath = "some CATPart file"
'Create a text stream from your FileSystemObject
Set sText = fsDataFile.OpenTextFile(sPath, 1, False)
'Loop through each line in the text stream
Done = False
Do While sText.AtEndOfStream <> True
line_n = line_n + 1
line = sText.ReadLine
'Some times the file contains the word more than once, the
'boolean variable Done avoid this problem.
If InStr(1, line, "ASMPRODUCT", 1) <> 0 And Done = False Then
Debug.Print line_n & " | PN: " & Mid(line, InStr(1, line,"ASMPRODUCT") + 11, 16)
Done = True
End If
Loop
sText.Close