Hello All,
I am trying to execute a VB program that will copy worksheets in a workbook into another workbook with some calculations done to it. However, after writing basic code and trying to debug I came across the message"Error 1004- Application or Object-defined error" at line 6(when opening first filename) and I am sure line 7 will give me the same prob.
Application.ScreenUpdating = False
intRow = 2
strPath = Workbooks("Budget_Macro.xls").Sheets("Budget").Range("E2")
strTemplate = "All Cinemas Phased.xls"
strCSV = "Cinemas CSV 2005.xls"
Application.StatusBar = "Opening Files"
Workbooks.Open Filename:=strPath & strTemplate
Workbooks.Open Filename:=strPath & strCSV
Do Until Workbooks("Budget_Macro.xls").Sheets("Budget").Range("A" & intRow) = ""
strCinema = Workbooks("Budget_Macro.xls").Sheets("Budget").Range("A" & intRow)
strRate = Workbooks("Budget_Macro.xls").Sheets("Budget").Range("C" & intRow)
strCSA = Workbooks("Budget_Macro.xls").Sheets("Budget").Range("D" & intRow)
Application.StatusBar = "Creating Template " & strCinema
Workbooks(strTemplate).Sheets(strCinema).Range("D77") = strRate
Workbooks(strTemplate).Sheets(strCinema).Range("Q10") = strCSA
Workbooks(strTemplate).Sheets(strCinema).Range("Q20") = strCSA
'Create a template suitable for CSV file inclusive of cost calculations
' as well as numbers being values only
Workbooks(strTemplate).Sheets(strCinema).Cells.Copy
Workbooks(strCSV).Sheets(strCinema).Range("A1").PasteSpecial xlValues
Workbooks(strCSV).Sheets(strCinema).Range("D60:O66").Formula = "=D8-D18"
Workbooks(strCSV).Sheets(strCinema).Range("D60:O66").Copy
Workbooks(strCSV).Sheets(strCinema).Range("D18:O24").PasteSpecial xlValues
Workbooks(strCSV).Sheets(strCinema).Range("C60:O103") = 0
intRow = intRow + 1
Loop
Application.DisplayAlerts = False
Application.CutCopyMode = False
Application.StatusBar = False
End Sub
Thank you and reply A.S.A.P
romij29
I am trying to execute a VB program that will copy worksheets in a workbook into another workbook with some calculations done to it. However, after writing basic code and trying to debug I came across the message"Error 1004- Application or Object-defined error" at line 6(when opening first filename) and I am sure line 7 will give me the same prob.
Application.ScreenUpdating = False
intRow = 2
strPath = Workbooks("Budget_Macro.xls").Sheets("Budget").Range("E2")
strTemplate = "All Cinemas Phased.xls"
strCSV = "Cinemas CSV 2005.xls"
Application.StatusBar = "Opening Files"
Workbooks.Open Filename:=strPath & strTemplate
Workbooks.Open Filename:=strPath & strCSV
Do Until Workbooks("Budget_Macro.xls").Sheets("Budget").Range("A" & intRow) = ""
strCinema = Workbooks("Budget_Macro.xls").Sheets("Budget").Range("A" & intRow)
strRate = Workbooks("Budget_Macro.xls").Sheets("Budget").Range("C" & intRow)
strCSA = Workbooks("Budget_Macro.xls").Sheets("Budget").Range("D" & intRow)
Application.StatusBar = "Creating Template " & strCinema
Workbooks(strTemplate).Sheets(strCinema).Range("D77") = strRate
Workbooks(strTemplate).Sheets(strCinema).Range("Q10") = strCSA
Workbooks(strTemplate).Sheets(strCinema).Range("Q20") = strCSA
'Create a template suitable for CSV file inclusive of cost calculations
' as well as numbers being values only
Workbooks(strTemplate).Sheets(strCinema).Cells.Copy
Workbooks(strCSV).Sheets(strCinema).Range("A1").PasteSpecial xlValues
Workbooks(strCSV).Sheets(strCinema).Range("D60:O66").Formula = "=D8-D18"
Workbooks(strCSV).Sheets(strCinema).Range("D60:O66").Copy
Workbooks(strCSV).Sheets(strCinema).Range("D18:O24").PasteSpecial xlValues
Workbooks(strCSV).Sheets(strCinema).Range("C60:O103") = 0
intRow = intRow + 1
Loop
Application.DisplayAlerts = False
Application.CutCopyMode = False
Application.StatusBar = False
End Sub
Thank you and reply A.S.A.P
romij29