Solved

Have scheduled task save an excel sheet

Posted on 2014-04-22
4
267 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

728 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