I am creating a workbook that will import material stream component flows (Mass, Molar, and Volumetric) from HYSYS. I have written 90% of the code, but cannot get part of it to work correctly. I would use HYSYS Stream Reader for this, but I want this workbook to be able to pull the data, format it, and print it according to a template I have created. I'll paste the code below:
Private Sub CommandButton1_Click()
Dim hycase As Object
Dim hyStream As ProcessStream
Dim Feed1, Feed2, Feed3, Feed4, Feed5, Feed6, Propane, Butane, Alkylate As String
Dim noCount As Integer
'Connect to HYSYS (must be open with target Case loaded)
Set hyapp = GetObject(, "HYSYS.Application")
hyapp.Visible = True
Set hycase = hyapp.ActiveDocument
'Get case name
Set CaseName = hycase.Title
Set hyFS = hycase.Flowsheet
Set hyOPers = hyFS.Operations
'Get reaction variables
Set Composite = hyFS.MaterialStreams("8")
Set Effluent = hyFS.MaterialStreams("9")
Set Contactors = hyOPers.Item("Contactors")
Set Data = Worksheets("Sheet1")
Set OP = Worksheets("Output")
OP.Cells(1, 7).Value = CaseName
Worksheets("Sheet1").Activate
Feed1 = Data.Cells(3, 2).Value
Feed2 = Data.Cells(4, 2).Value
Feed3 = Data.Cells(5, 2).Value
Feed4 = Data.Cells(6, 2).Value
Feed5 = Data.Cells(7, 2).Value
Feed6 = Data.Cells(8, 2).Value
Propane = Data.Cells(3, 5).Value
Butane = Data.Cells(4, 5).Value
Alkylate = Data.Cells(5, 5).Value
Cells(11, 11).Value = Feed1
If Feed1 <> "" Then
Set hyStream = hyFS.MaterialStreams.Item(Feed1)
For noCount = 1 To 55
MolarFlow = hyStream.ComponentMolarFlowValue
Worksheets("Output").Activate
Cells(noCount + 5, 2) = MolarFlow(noCount - 1) * 3600
Next noCount
End If
End Sub
Regarding the red text, Feed1 is equal to "1", or stream 1 in this case. It is imput on another spreadsheet as a feed stream to be pulled into the spreadsheet. The way the code is currently written, when run, it fills cells B6-B60 with the value -117961200. However, when I replace Feed1 with "1", the macro fills the pertinent cells with the correct values (kgmol/hr of the corresponding component). What am I missing here? I've tried converting Feed1 to a string but that did not work either.