[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Have scheduled task save an excel sheet

Posted on 2014-04-22
4
Medium Priority
?
269 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 668 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 46

Assisted Solution

by:aikimark
aikimark earned 1332 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 46

Assisted Solution

by:aikimark
aikimark earned 1332 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

649 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