cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

Problem connecting VBA to Creo

BC_10219589
9-Granite

Problem connecting VBA to Creo

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)"

vba_excel.PNG

 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

 

 

 

 

 

3 REPLIES 3

 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,

 

 

cko
11-Garnet
11-Garnet
(To:BC_10219589)

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 !

Announcements
NEW Creo+ Topics: Real-time Collaboration


Top Tags