Solved

Have scheduled task save an excel sheet

Posted on 2014-04-22
4
264 Views
Last Modified: 2014-05-09
Hi,
I am looking for a way to have a scheduled task save a excel sheet as a dated file name. From Test.xls to date 042214.xls. This needs to happen every night and the name of the orginal file will stay the same. I would also like the file to save all the formulas as values not as formulas. Can this be done?
Thanks
0
Comment
Question by:portillosjohn
  • 2
  • 2
4 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 167 total points
ID: 40016708
Hi, in terms of renaming it, we can do that outside of Excel, just by renaming the file.  This should also open Excel and change the cell values to plain text.

Note that as a scheduled task, there must be a user logged in all the time when this runs.

Regards,

Rob.

Set objFSO = CreateObject("Scripting.FileSystemObject")
strFile = "C:\Files\Test.xlsx"
strNewFile = "C:\Files\" & Right("0" & Month(Date), 2) & Right("0" & Day(Date), 2) & Right(Year(Date), 2) & ".xlsx"
objFSO.CopyFile strFile, strNewFile, True
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWB = objExcel.Workbooks.Open(strNewFile, False, False)
For Each objSheet In objWB.Sheets
	For Each objCell In objSheet.Cells
		objCell.Value = objCell.Text
	Next
Next
objWB.Save
objWB.Close True
objExcel.Quit

Open in new window

0
 
LVL 45

Assisted Solution

by:aikimark
aikimark earned 333 total points
ID: 40017484
@Rob

What is the performance of all cell iteration versus the worksheet's usedrange?

Assigning the .Text property wiped out cells in a test worksheet.

This version of your code seemed to work, replacing any formulas with their values.
For Each objSheet In objWB.Sheets
    objSheet.UsedRange.Value = objSheet.UsedRange.Value
Next

Open in new window

0
 
LVL 45

Assisted Solution

by:aikimark
aikimark earned 333 total points
ID: 40017510
If the sheets were large and had relatively few formulas (think sparse matrix), the following approach might be worth performance testing.
For Each objSheet In objWB.Sheets
    If objSheet.Cells.SpecialCells(xlCellTypeFormulas) Is Nothing Then
    Else
        For Each objArea In objSheet.Cells.SpecialCells(xlCellTypeFormulas)
            objArea.Value = objArea.Value
        Next
    End If
Next

Open in new window


Also, I usually advise suppressing any screen refreshing during bulk update operations like this one.
Example:
objExcel.ScreenUpdating = False
For Each objSheet In objWB.Sheets
    If objSheet.Cells.SpecialCells(xlCellTypeFormulas) Is Nothing Then
    Else
        For Each objArea In objSheet.Cells.SpecialCells(xlCellTypeFormulas)
            objArea.Value = objArea.Value
        Next
    End If
Next
objExcel.ScreenUpdating = True

Open in new window

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 40018133
Thanks Aikimark. Admittedly I didn't test it, and probably should have stated that, but I am surprised the .Text property wiped the values, and that assigning .Value as .Value removed the formula. I realise there is a .FormulaR1C1 property, but it still surprises me.

Thanks for the performance updates.  Usually for scheduled tasks I don't concern myself with performance, since they aren't typically time critical.

Rob.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question