snoopydoopy
New member
- Local time
- Today, 01:08
- Joined
- Oct 23, 2014
- Messages
- 9
Pls see below. It's opening up the file but it's not running the macro which is on another file quoting error 1004 - saying macro may not exist or similar (it does).
It also opens up the file as read only..
so instead of running a macro - how do I copy the sub of the macro in this instead?
Original:
Sub RunExcelMacro()
Dim xl As Object
'Step 1: Start Excel, then open the target workbook.
Set xl = CreateObject("Excel.Application")
xl.Workbooks.Open ("Y:\Operational Forecasting\0.1 Depot Forecast\Daily_Extracts\FRSH_Total_Demand_By_Day_By_Depot_By_Dept_Sect\FRSH_Total_Demand_By_Day_By_Depot_By_Dept_Sect_03102014.xlsx")
'Step 2: Make Excel visible
xl.Visible = True
'Step 3: Run the target macro (this file is another file with the macro in it)
xl.Run "Y:\Operational Forecasting\0.1 Depot Forecast\Daily_Extracts\FRSH_Total_Demand_By_Day_By_Depot_By_Dept_Sect\Copy of FRSH_Total_Demand_By_Day_By_Depot_By_Dept_Sect_03102014a.xlsm!Summarise"
'Step 4: Close and save the workbook, then close Excel (is this ok, as it needs to saved as macro-enabled now??)
xl.ActiveWorkbook.SaveAs fPath & tDate & ".xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled
xl.Quit
'Step 5: Memory Clean up.
Set xl = Nothing
End Sub
---
The macro itself, which I rather just put into the vba rather than running form somewhere else but don't know where to place it in the code above.. how to edit:
Sub Summarise()
Sheets(Array("Qry_Total_Demand_By_Dept_Sectio", _
"Qry_Demand_SAM_By_Dept_Section_", "Qry_Demand_ESM_By_Dept_Section_")).Select
Sheets("Qry_Total_Demand_By_Dept_Sectio").Activate
Rows("1:1").Select
Sheets("Qry_Total_Demand_By_Dept_Sectio").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$AW$373").AutoFilter Field:=3, Criteria1:= _
"STORE EXPENSES"
Columns("B:B").Select
Selection.Delete Shift:=xlToLeft
Range("C1").Select
ActiveCell.FormulaR1C1 = "ForecastID:[]"
Range("C43:C373").Select
Selection.ClearContents
Columns("D
").Select
Selection.Delete Shift:=xlToLeft
Rows("1:373").Select
Selection.Copy
Sheets.Add After:=ActiveSheet
ActiveSheet.Paste
End Sub
It also opens up the file as read only..
so instead of running a macro - how do I copy the sub of the macro in this instead?
Original:
Sub RunExcelMacro()
Dim xl As Object
'Step 1: Start Excel, then open the target workbook.
Set xl = CreateObject("Excel.Application")
xl.Workbooks.Open ("Y:\Operational Forecasting\0.1 Depot Forecast\Daily_Extracts\FRSH_Total_Demand_By_Day_By_Depot_By_Dept_Sect\FRSH_Total_Demand_By_Day_By_Depot_By_Dept_Sect_03102014.xlsx")
'Step 2: Make Excel visible
xl.Visible = True
'Step 3: Run the target macro (this file is another file with the macro in it)
xl.Run "Y:\Operational Forecasting\0.1 Depot Forecast\Daily_Extracts\FRSH_Total_Demand_By_Day_By_Depot_By_Dept_Sect\Copy of FRSH_Total_Demand_By_Day_By_Depot_By_Dept_Sect_03102014a.xlsm!Summarise"
'Step 4: Close and save the workbook, then close Excel (is this ok, as it needs to saved as macro-enabled now??)
xl.ActiveWorkbook.SaveAs fPath & tDate & ".xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled
xl.Quit
'Step 5: Memory Clean up.
Set xl = Nothing
End Sub
---
The macro itself, which I rather just put into the vba rather than running form somewhere else but don't know where to place it in the code above.. how to edit:
Sub Summarise()
Sheets(Array("Qry_Total_Demand_By_Dept_Sectio", _
"Qry_Demand_SAM_By_Dept_Section_", "Qry_Demand_ESM_By_Dept_Section_")).Select
Sheets("Qry_Total_Demand_By_Dept_Sectio").Activate
Rows("1:1").Select
Sheets("Qry_Total_Demand_By_Dept_Sectio").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$AW$373").AutoFilter Field:=3, Criteria1:= _
"STORE EXPENSES"
Columns("B:B").Select
Selection.Delete Shift:=xlToLeft
Range("C1").Select
ActiveCell.FormulaR1C1 = "ForecastID:[]"
Range("C43:C373").Select
Selection.ClearContents
Columns("D
Selection.Delete Shift:=xlToLeft
Rows("1:373").Select
Selection.Copy
Sheets.Add After:=ActiveSheet
ActiveSheet.Paste
End Sub