Consulting

Results 1 to 7 of 7

Thread: Error combining VBA - SuperPro Designer

  1. #1
    VBAX Regular
    Joined
    Nov 2015
    Posts
    17
    Location

    Error combining VBA - SuperPro Designer

    Hi all,

    I encountered this error while running VBA code.

    Run-time error '-2147417848 (80010108)': Automation error, the object invoked has disconnected from its client.

    The VBA code is connected to Superpro designer. The aims of the VBA are to set the value in the process simulation and get the final mass balance.

    Anyone encountered this before?

    Thanks in advance.

    Elizabeth

  2. #2
    VBAX Expert
    Joined
    Oct 2012
    Posts
    726
    Location
    Sure, the object has been closed but not set to nothing. This gives the same error...

    Sub test()    Dim w As Word.Application
        Dim d As Word.Document
        
        Set w = New Word.Application: w.Visible = True
        
        'Create a new document and close it
        Set d = w.Documents.Add: d.Close False
        
        On Error Resume Next
        Debug.Print d.Name '<--- CANNOT GET NAME SINCE OBJECT IS CLOSED
        Debug.Print Err.Number, Err.Description
        
        w.Quit
        
    End Sub

  3. #3
    VBAX Regular
    Joined
    Nov 2015
    Posts
    17
    Location
    Hi jonh,
    thanks for your reply.

    I did the same but without closing it.


    Function dir(input as double) as variant
    
    Dim superProApp As Designer.Application
    Dim superProDoc As Designer.Document
    
    Set superProApp = New Designer.Application
    Set superProDoc = superProApp.OpenDoc("D:\xxx.spf")
    
    . 'this is where the code is written. it is quite long so i dont paste it here.
    .
    .
    
    dir  = result
    
    
    End Function
    In the code I wrote, there is no close routine.

    Is that what you meant? Sorry if I misunderstood.

  4. #4
    VBAX Regular
    Joined
    Nov 2015
    Posts
    17
    Location
    Hi jonh,

    I solved the problem. I dont know why but the error does not appear anymore when I introduced the close routine.

    superProDoc.CloseDoc False
    superProApp.CloseApp
    Thanks for helping!

    Elizabeth

  5. #5
    VBAX Newbie
    Joined
    Jan 2018
    Posts
    3
    Location
    Hi everyone, I´m new in this forum
    Anyone knows what ByRef means? and how to fix it? I cannot solve this

  6. #6
    VBAX Newbie
    Joined
    Jan 2018
    Posts
    3
    Location
    If superProApp Is Nothing Then MsgBox "First open a SuperPro Designer case file."
    Exit Sub
    End If

    Set ws = Worksheets("Throughput Analysis")

    compFlow = ws.range("D10")
    increase = ws.range("D11")

    Application.Cursor = xlWait
    Application.DisplayStatusBar = True
    Application.StatusBar = "Please wait while script is running ..."

    ws.range("A19") = "Performing Calculations for"
    ws.range("A18:A22").Interior.Color = RGB(255, 128, 0)
    ws.range("A21") = "Batch Throughput " & throughput & " kg/batch"
    SetAndGetIngredientFlow compFlow
    ws.range("B16") = compFlow

    Dim dCell As range
    For Each dCell In range("B17:B40")

    compFlow = compFlow + increase
    ws.range("A21") = "Batch Throughput " & throughput & " kg/batch"
    SetAndGetIngredientFlow compFlow [I have ByRef issues with this compFlow]
    dCell = compFlow

    ws.range("A21") = Empty
    Next dCell

    ws.range("A19") = Empty
    ws.range("A18:A22").Interior.ColorIndex = xlNone
    Application.Cursor = xlDefault
    Application.StatusBar = False
    End Sub

  7. #7
    VBAX Newbie
    Joined
    Jan 2018
    Posts
    3
    Location
    Here you can find how I declare it

    'Global Declarations
    Public superProApp As Designer.Application
    Public superProDoc As Designer.Document


    'Module 1 Declarations
    Dim var1 As Variant
    Dim var2 As Variant
    Dim str1 As String
    Dim str2 As String
    Dim streamName As String
    Dim componentName As String




    'Throughput and Economic Indices Functions


    'Set And Get Antocyanin Flow
    Function SetAndGetIngredientFlow(streamName As String, componentName As String, compFlow As Double) As Double


    str1 = CStr(streamName)
    str2 = CStr(componentName)
    var2 = CDbl(compFlow)


    streamName = "Quinaldine"
    componentName = "Quinaldine"


    superProDoc.SetStreamVarVal str1, VarID.componentMassFlow_VID, var1, str2

    'Solve Mass & Energy Balances
    superProDoc.DoMEBalances var1
    'Economic Calculations
    superProDoc.DoEconomicCalculations

    superProDoc.GetStreamVarVal str1, VarID.componentMassFlow_VID, var2, str2
    SetAndGetIngredientFlow = CDbl(var2)


    End Function

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •