S
Sean
I wish to open an Excel file via a script and run a specified macro,
then save the file at a certain time each day. I looked up the
Microsoft site and found the code below which Opens all files in a
directory, runs a macro on all then closes. It pretty much does what I
want except I just have one specified file, problem is I'm not sure
what part of the code I change, I just can't work it out.
Hope someone can help
Important information I guess is
Path where file exists: T:\2008\sean\my documents\Daily Report.xls
(this is a mapped drive on my PC)
Macro name: CompileReport
Code from Microsoft site below-
strComputer = "tvsfrank"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root
\cimv2")
Set colFileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='C:\Test'} Where " _
& "ResultClass = CIM_DataFile")
Set objExcel = CreateObject("Excel.Application", strComputer)
objExcel.DisplayAlerts = False
For Each objFile In colFileList
If objFile.Extension = "xls" Then
Set objWorkbook = objExcel.Workbooks.Open(objFile.Name)
Set objWorksheet = objWorkbook.Worksheets(1)
objExcel.Run("BoldfaceHeadings")
objWorkbook.SaveAs objFile.Name
objWorkbook.Close
End If
Next
objExcel.Quit
then save the file at a certain time each day. I looked up the
Microsoft site and found the code below which Opens all files in a
directory, runs a macro on all then closes. It pretty much does what I
want except I just have one specified file, problem is I'm not sure
what part of the code I change, I just can't work it out.
Hope someone can help
Important information I guess is
Path where file exists: T:\2008\sean\my documents\Daily Report.xls
(this is a mapped drive on my PC)
Macro name: CompileReport
Code from Microsoft site below-
strComputer = "tvsfrank"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root
\cimv2")
Set colFileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='C:\Test'} Where " _
& "ResultClass = CIM_DataFile")
Set objExcel = CreateObject("Excel.Application", strComputer)
objExcel.DisplayAlerts = False
For Each objFile In colFileList
If objFile.Extension = "xls" Then
Set objWorkbook = objExcel.Workbooks.Open(objFile.Name)
Set objWorksheet = objWorkbook.Worksheets(1)
objExcel.Run("BoldfaceHeadings")
objWorkbook.SaveAs objFile.Name
objWorkbook.Close
End If
Next
objExcel.Quit