Hi All,
The procedure listed below gives me the above error which I am sure must be an easy fix but my very limited knowledge can't seem to figure it out. I swear this was working when I first made it but now I get the error at the indicated (by asterisks) line of code. If any one can point me in the right direction it would be most appreciated.
A little background, I work in a utility . We have programmable logic controllers that operate stations and send data back to a sequel server for collection. On the server we have an excel spreadsheet app that displays all the stations reads as of 7 AM. Some stations are not online and are done manually. A different macro is run daily after the manual update and populates a monthly log (each station has it's own sheet) in a format the operators are familiar with. The macro below grabs the end of month reads from the previous month's file and paste them to the FWD row of the current month's file. I hope I've given enough info.
Sub Update_FWD()
'
' Update_FWD Macro
' Macro recorded 4/8/2003
'
' Current month's file is already open
Worksheets("Update_FWD_Reads"
.Activate
'
' Declare Variables
'
Dim strCurrentMonth As String
Dim strLastMonthFile As String
Dim strLastMonth As String
' -----------------------------------------------------------------
' Assign values to variables
'
' The following variable is the current month file with
' the path, hidden cell K5 on the Update_FWD_Reads
' worksheet calculates the value of the current month
strCurrentMonth = "C:\Data\MonthlyStationLogs\" & Format([K5], "mmm-yyyy"
& ".xls"
' The following variable is a path to a file named with
' the month previous to the one reported in cell K5,
' ex. Aug-2002.xls
' Hidden cell K7 on the Update_FWD_Reads worksheet
' calculates this value
strLastMonthFile = "C:\Data\MonthlyStationLogs\" & Format([K7], "mmm-yyyy"
& ".xls"
' The following variable is the previous month file
' without the path
strLastMonth = Format([K7], "mmm-yyyy"
& ".xls"
' ---------------------------------------------------------
'
' Open last month's file and copy the reads from the
' last day of all sheets
Workbooks.Open (strLastMonthFile)
Sheets(Array("S-2", "S-4", "S-5", "S-6", "S-7", "S-8", "S-9", "S-10", "S-11", "S-12"
). _
Select
Sheets("S-2"
.Activate
Range("C38:N38"
.Copy
' Paste last month's reads to current month's FWD row
*** Windows(strCurrentMonth).Activate ***
Sheets(Array("S-2", "S-4", "S-5", "S-6", "S-7", "S-8", "S-9", "S-10", "S-11", "S-12"
). _
Select
Range("C6:N6"
.Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range("A1"
.Select
Sheets("S-2"
.Select
Range("A1"
.Select
Workbook.Activate (strCurrentMonth)
ActiveWorkbook.Save
'
' Close last month's file
Windows(strLastMonth).Activate
Sheets("S-2"
.Select
Range("A1"
.Select
ActiveWindow.Close
' Current month’s file is left updated and open
End Sub
The procedure listed below gives me the above error which I am sure must be an easy fix but my very limited knowledge can't seem to figure it out. I swear this was working when I first made it but now I get the error at the indicated (by asterisks) line of code. If any one can point me in the right direction it would be most appreciated.
A little background, I work in a utility . We have programmable logic controllers that operate stations and send data back to a sequel server for collection. On the server we have an excel spreadsheet app that displays all the stations reads as of 7 AM. Some stations are not online and are done manually. A different macro is run daily after the manual update and populates a monthly log (each station has it's own sheet) in a format the operators are familiar with. The macro below grabs the end of month reads from the previous month's file and paste them to the FWD row of the current month's file. I hope I've given enough info.
Sub Update_FWD()
'
' Update_FWD Macro
' Macro recorded 4/8/2003
'
' Current month's file is already open
Worksheets("Update_FWD_Reads"
'
' Declare Variables
'
Dim strCurrentMonth As String
Dim strLastMonthFile As String
Dim strLastMonth As String
' -----------------------------------------------------------------
' Assign values to variables
'
' The following variable is the current month file with
' the path, hidden cell K5 on the Update_FWD_Reads
' worksheet calculates the value of the current month
strCurrentMonth = "C:\Data\MonthlyStationLogs\" & Format([K5], "mmm-yyyy"
' The following variable is a path to a file named with
' the month previous to the one reported in cell K5,
' ex. Aug-2002.xls
' Hidden cell K7 on the Update_FWD_Reads worksheet
' calculates this value
strLastMonthFile = "C:\Data\MonthlyStationLogs\" & Format([K7], "mmm-yyyy"
' The following variable is the previous month file
' without the path
strLastMonth = Format([K7], "mmm-yyyy"
' ---------------------------------------------------------
'
' Open last month's file and copy the reads from the
' last day of all sheets
Workbooks.Open (strLastMonthFile)
Sheets(Array("S-2", "S-4", "S-5", "S-6", "S-7", "S-8", "S-9", "S-10", "S-11", "S-12"
Select
Sheets("S-2"
Range("C38:N38"
' Paste last month's reads to current month's FWD row
*** Windows(strCurrentMonth).Activate ***
Sheets(Array("S-2", "S-4", "S-5", "S-6", "S-7", "S-8", "S-9", "S-10", "S-11", "S-12"
Select
Range("C6:N6"
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Range("A1"
Sheets("S-2"
Range("A1"
Workbook.Activate (strCurrentMonth)
ActiveWorkbook.Save
'
' Close last month's file
Windows(strLastMonth).Activate
Sheets("S-2"
Range("A1"
ActiveWindow.Close
' Current month’s file is left updated and open
End Sub