Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X
Hello All,
I have been trying to run the following code as a Macro on Excel to get the name of current model open in Creo :
Sub Macro1()
Dim asynconn As New pfcls.CCpfcAsyncConnection
Dim conn As pfcls.IpfcAsyncConnection
Dim session As pfcls.IpfcBaseSession
Dim mdlname
Set conn = asynconn.Connect("", "", ".", 5)
Set session = conn.session
mdlname = session.CurrentModel.Filename
Range("A1").Select
ActiveCell.FormulaR1C1 = mdlname
MsgBox ("Name: " & mdlname)
conn.Disconnect (2)
End Sub
However, I get the following issue when entering the line of "Set conn = asynconn.Connect("", "", ".", 5)"
I have already added PRO_COMM_MSG_EXE to my system variables, run vb_api_register.bat adn added creo library to the references.
Does anybody know how can I fix this issue?
Thank you in advance
Hi,
1. Read the following articles:
2. There was a similar question before - "VBA run-time error -2147352567(80020009)": https://community.ptc.com/t5/Creo-Modeling-Questions/VBA-run-time-error-2147352567-80020009/td-p/189086
Hello,
Thank you for your help, I still get the error message though in line "Set conn = asynconn.Connect("", "", ".", 5)" and I think it might be caused because the program does not find the owring directory, do you know how can I declare it? I saved it in the system variables but it does not seem to work
Thank you,
Enter the currently active model name in "A1" CELLS.
Sub ModelName()
Dim asynconn As New pfcls.CCpfcAsyncConnection
Dim conn As pfcls.IpfcAsyncConnection: Set conn = asynconn.Connect("", "", ".", 5)
Dim oSession As pfcls.IpfcBaseSession: Set oSession = conn.session
Dim oModel As IpfcModel: Set oModel = oSession.CurrentModel
'Model File location
Cells(2, "C") = oSession.GetCurrentDirectory
'Model File Name
Cells(1, "C") = oModel.Filename
conn.Disconnect (2)
'Cleanup
Set asynconn = Nothing
Set conn = Nothing
Set session = Nothing
Set model = Nothing
End Sub
* Sample Code : Blog -> https://tool-2020.tistory.com/556
good luck !