Private Sub CommandButton3_Click()
Dim OtherBook As String
Dim ProjDir As String
Dim ProjOutDir As String
Dim ResultsFile As String
Dim i As Integer
Dim j As Integer
Dim ManageArray() As String
Dim LastCol As Integer
'get values for project directory, output folder, batch numbers, batch run labels,
'output file names, results filename, weather file
With Sheets("Manage")
ProjDir = .Cells(4, "G").Value
ProjOutDir = .Cells(5, "G").Value
ResultsFile = .Cells(6, "G").Value
End With
With Sheets("Batch Runs")
'Get last column:
LastCol = .Cells(3, .Columns.Count).End(xlToLeft).Column
'Fill an array with run number, base filename, batch run label, and location
Debug.Print LastCol
ReDim ManageArray(1 To LastCol - 1, 1 To 5)
For i = 1 To LastCol - 1
ManageArray(i, 1) = i
ManageArray(i, 2) = .Cells.Find(What:="RUN", After:=.Cells(1, 1), LookIn:=xlValues, LookAt:=xlPart, SearchDirection:=xlNext, _
MatchCase:=True, SearchFormat:=False).Offset(0, i)
ManageArray(i, 3) = .Cells.Find(What:="Base Filename", After:=.Cells(1, 1), LookIn:=xlValues, LookAt:=xlPart, SearchDirection:=xlNext, _
MatchCase:=True, SearchFormat:=False).Offset(0, i)
ManageArray(i, 4) = .Cells.Find(What:="Batch Run Label", After:=.Cells(1, 1), LookIn:=xlValues, LookAt:=xlPart, SearchDirection:=xlNext, _
MatchCase:=True, SearchFormat:=False).Offset(0, i)
ManageArray(i, 5) = .Cells.Find(What:="Location", After:=.Cells(1, 1), LookIn:=xlValues, LookAt:=xlPart, SearchDirection:=xlNext, _
MatchCase:=True, SearchFormat:=False).Offset(0, i)
Next i
Debug.Print ManageArray(1, 1)
Debug.Print ManageArray(1, 2)
Debug.Print ManageArray(1, 3)
Debug.Print ManageArray(1, 4)
Debug.Print ManageArray(1, 5)
Debug.Print ManageArray(2, 1)
Debug.Print ManageArray(2, 2)
Debug.Print ManageArray(2, 3)
Debug.Print ManageArray(2, 4)
End With
'open eQuest extract file, rename it, and put the data onto sheet 2
'test if the file exists first.
'Debug.Print ProjDir + "\" + ResultsFile
If Len(Dir(ProjDir + "\Model Manager Extract Companion.xlsm")) > 0 Then
Workbooks.Open Filename:=ProjDir + "\Model Manager Extract Companion.xlsm"
OtherBook = ActiveWorkbook.Name
With Sheets("Manager")
.Cells(4, "B").Value = ProjDir
.Cells(5, "B").Value = ProjOutDir
.Cells(6, "B").Value = ResultsFile
For i = LBound(ManageArray, 1) To UBound(ManageArray, 1)
.Cells(8, i + 1).Value = ManageArray(i, 1)
.Cells(9, i + 1).Value = ManageArray(i, 2)
.Cells(10, i + 1).Value = ManageArray(i, 3)
.Cells(11, i + 1).Value = ManageArray(i, 4)
.Cells(12, i + 1).Value = ManageArray(i, 5)
.Cells(13, i + 1).Value = ManageArray(i, 3) + " - " + ManageArray(i, 4) _
+ " - Baseline Design"
Next i
End With
'call the function in the Model Manager Extract Companion
'Debug.Print ProjDir + "\" + "Model Manager Extract Companion.xlsm!CallD2ResultsFunction"
Application.Run "Model Manager Extract Companion.xlsm!CallD2ResultsFunction"
Else
'File does not exist
MsgBox "Model Manager Extract Companion.xlsm not found. Please ensure you have a copy of this file with this name in the project folder listed on the model manager."
End If
Bookmarks