Solved

Have scheduled task save an excel sheet

Posted on 2014-04-22
4
262 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now