View Full Version : [SOLVED:] Error combining VBA - SuperPro Designer
evalent
11-05-2015, 12:46 AM
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
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
evalent
11-06-2015, 12:24 AM
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.
evalent
11-06-2015, 12:35 AM
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
marucina
01-16-2018, 05:29 AM
Hi everyone, I´m new in this forum
Anyone knows what ByRef means? and how to fix it? I cannot solve this :crying:
marucina
01-16-2018, 05:31 AM
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
marucina
01-16-2018, 05:32 AM
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
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.