I have a VBA macro in an excel. The macro opens another work inorder to copy a sheet into the active wookbook. When the open command executes the macro stops. I've tried this in and out of the debugger. I have tried several methods of coding the desired action (copy sheet from workbook into my active workbook). All versions stop on the workbook open call.
I even tried the submitted code MVP Bill Jelen on the MSDN stie.
Sub UpdateActualCosts()
'''''''''''''''''''''''''''
'''' NOT WORKING YET
'''''''''''''''''''''''''''
Dim HistoryRptLoc As String
Dim HistoryRptWookBook As String
Dim CostActualName As String
Dim ProjName As String
Dim HistWkBk As Workbook
Dim Criteria As String
Dim MaxDate As Integer
Dim MaxDateRng As Range
Dim iLastRow As Integer
Dim ControlFile As String
HistoryRptLoc = "\\\\mo-users\\\Financial\\"
HistoryRptWookBook = "FY2015 Labor History.xlsx"
CostActualName = "FY2015"
ThisWorkbook.Sheets("Project_Definition").Activate
ProjName = ActiveSheet.Range("Project_Definition!B2").Value
' open spreadsheet from remote location
ControlFile = ActiveWorkbook.Name
Workbooks.Open FileName:=HistoryRptLoc & HistoryRptWookBook
' the following code never executes - the file does open - it is a xlsx type file
ActiveSheet.Name = CostActualName
Sheets(CostActualName).Copy After:=Workbooks(ControlFile).Sheets("Performance")
Windows(HistoryRptWookBook).Activate
ActiveWorkbook.Close SaveChanges:=False
Windows(ControlFile).Activate
' get the max date in the first column
ThisWorkbook.Sheets(CostActualName).Activate
ActiveSheet.Select
ActiveSheet.Range("A1").Select
Selection.End(xlDown).Select
iLastRow = ActiveWindow.RangeSelection.Row
MaxDateRng = Range("A1:A" + CStr(iLastRow))
MaxDate = Application.WorksheetFunction.Max(MaxDateRng)
' filter for time and project
With Range("A1:H1")
.AutoFilter
.AutoFilter Field:=1, Criteria1:=CStr(MaxDate)
End With
' for each row in filtered range
' look up person - return rate
' AccumCharges += rate * hours
End Sub
I even tried the submitted code MVP Bill Jelen on the MSDN stie.
Sub UpdateActualCosts()
'''''''''''''''''''''''''''
'''' NOT WORKING YET
'''''''''''''''''''''''''''
Dim HistoryRptLoc As String
Dim HistoryRptWookBook As String
Dim CostActualName As String
Dim ProjName As String
Dim HistWkBk As Workbook
Dim Criteria As String
Dim MaxDate As Integer
Dim MaxDateRng As Range
Dim iLastRow As Integer
Dim ControlFile As String
HistoryRptLoc = "\\\\mo-users\\\Financial\\"
HistoryRptWookBook = "FY2015 Labor History.xlsx"
CostActualName = "FY2015"
ThisWorkbook.Sheets("Project_Definition").Activate
ProjName = ActiveSheet.Range("Project_Definition!B2").Value
' open spreadsheet from remote location
ControlFile = ActiveWorkbook.Name
Workbooks.Open FileName:=HistoryRptLoc & HistoryRptWookBook
' the following code never executes - the file does open - it is a xlsx type file
ActiveSheet.Name = CostActualName
Sheets(CostActualName).Copy After:=Workbooks(ControlFile).Sheets("Performance")
Windows(HistoryRptWookBook).Activate
ActiveWorkbook.Close SaveChanges:=False
Windows(ControlFile).Activate
' get the max date in the first column
ThisWorkbook.Sheets(CostActualName).Activate
ActiveSheet.Select
ActiveSheet.Range("A1").Select
Selection.End(xlDown).Select
iLastRow = ActiveWindow.RangeSelection.Row
MaxDateRng = Range("A1:A" + CStr(iLastRow))
MaxDate = Application.WorksheetFunction.Max(MaxDateRng)
' filter for time and project
With Range("A1:H1")
.AutoFilter
.AutoFilter Field:=1, Criteria1:=CStr(MaxDate)
End With
' for each row in filtered range
' look up person - return rate
' AccumCharges += rate * hours
End Sub