Solved

Save file with creation date

Posted on 2013-02-03
7
321 Views
Last Modified: 2013-02-03
Hello,

I've added row 23-27 to my code to save the active sheet with the created date and time  stamp from the file that was used to import sheet one. It's bugging out on row 27. The file will save if I "Dim asof As Long" but the result is not what I require.

Sub ImportSheet()

        Dim fileName
        Dim wb As Workbook
        Dim strPath As String
        Dim fs, f
        Dim asof As String
        

        fileName = Application.GetOpenFilename("Other Workbook (*.xl*),*.xl*")
        If fileName = "False" Then
        MsgBox "You have not selected a file. Please try again."
        GoTo QuitSub
        End If
        Set wb = Workbooks.Open(fileName:=fileName)
        With ThisWorkbook
            wb.Worksheets(1).Copy After:=.Worksheets(.Worksheets.Count)
            wb.Close False
            .Activate
            .Worksheets(.Worksheets.Count).Select
        End With
        
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set f = fs.GetFile(fileName)
        asof = f.DateCreated
        strPath = ThisWorkbook.Path
        ActiveWorkbook.SaveAs strPath & Application.PathSeparator & "Data as of " & asof
        
        
QuitSub:
End Sub

Open in new window

0
Comment
Question by:sq30
  • 3
  • 2
  • 2
7 Comments
 
LVL 45

Expert Comment

by:Martin Liss
ID: 38849435
What do you get and what do you want?

You could try changing asof to Date, or if you want today's date just do

ActiveWorkbook.SaveAs strPath & Application.PathSeparator & "Data as of " & Now()
0
 

Author Comment

by:sq30
ID: 38849440
I want the creation date and time stamp of the file I used to import data from.
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 38849460
And what do you get instead?
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:sq30
ID: 38849467
An error have you read the question?
0
 
LVL 26

Accepted Solution

by:
redmondb earned 500 total points
ID: 38849471
sq30,

Replace the "SaveAs" line by...
ActiveWorkbook.SaveAs strPath & Application.PathSeparator & "Data as of " & WorksheetFunction.Substitute(WorksheetFunction.Substitute(asof, "/", "-"), ":", "-")

Brian.
0
 

Author Closing Comment

by:sq30
ID: 38849474
Thank you Brian.
0
 
LVL 26

Expert Comment

by:redmondb
ID: 38849477
Thanks, sq30.

Better is...
ActiveWorkbook.SaveAs strPath & Application.PathSeparator & "Data as of " & Replace(Replace(asof, "/", "-"), ":", "-")

Brian.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
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;…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

747 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

13 Experts available now in Live!

Get 1:1 Help Now