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
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 + "\" + ResultsFile)) > 0 Then
Workbooks.Open Filename:=ProjDir + "\" + ResultsFile
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
If Len(Dir(ProjDir + "\Model Manager Extract Companion.xlsm")) > 0 Then
'call the function in the Model Manager Extract Companion
'Debug.Print ProjDir + "\" + "Model Manager Extract Companion.xlsm!CallD2ResultsFunction"
ActiveWorkbook.Application.Run ProjDir + "\" + "'Model Manager Extract Companion.xlsm!CallD2ResultsFunction'"
Else
'File does not exist
MsgBox ProjDir + "\Model Manager Extract Companion.xlsm not found. Please ensure this file is in your project directory."
End If
Else
'File does not exist
MsgBox ResultsFile + " does not exist. Please ensure you have a copy of this file with this name in the project folder listed on the model manager."
End If
End Sub
Bookmarks