Hello,
I have written a macro that copies arange of worksheets from one workbook to another, however there seems to be a problem with getting the workbook to open even though the pathway has been specified and everything seems to be alright. Not sure what the problem is,but I did delete the file a few days ago and replaced it with an updated version. The code is:
Public Sub CSV_Template()
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 (This is the line that gives me Error 1004)
Workbooks.Open Filename:=strPath & strCSV (However this line opens perfectly!)
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
Thanks,
romij29
I have written a macro that copies arange of worksheets from one workbook to another, however there seems to be a problem with getting the workbook to open even though the pathway has been specified and everything seems to be alright. Not sure what the problem is,but I did delete the file a few days ago and replaced it with an updated version. The code is:
Public Sub CSV_Template()
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 (This is the line that gives me Error 1004)
Workbooks.Open Filename:=strPath & strCSV (However this line opens perfectly!)
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
Thanks,
romij29