Solved

Have scheduled task save an excel sheet

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
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…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

896 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

16 Experts available now in Live!

Get 1:1 Help Now