Solved

Add a Date to a File Name.

Posted on 2012-03-15
3
241 Views
Last Modified: 2012-03-15
ive got the following code that removes a password from an excel file.
but my filename is located in the variable User::ImportFileDir. so its basically the path then /adm.

because the file will be using the current date i want to add the date as follows. YYYMMDD.

so it will be ------Value) + "sdate" +".xls"). were sdate is a string with the date.

filename admYYYMMDD

i have the folowing code but it does not work.
---------------------------------------------------------------
        Dim sdate As Date
        sdate = Right("00" & Year(Now()), 2) & Right("0" & Month(Now()), 2) & Right("00" & Day(Now()), 2)

        MessageBox.Show("sdate")

-----------------------------------------------------------

        Dim objExcel As Object
        Dim objWorkbook As Object

        objExcel = CreateObject("Excel.Application")

        objExcel.Visible = False



        objWorkbook = objExcel.Workbooks.Open("\\" + Str(Dts.Variables("User::ImportFileDir").Value) + "\" + Str(Dts.Variables("User::ImportFileDir").Value) + ".xls", , , , "test")

        objExcel.DisplayAlerts = False

        objWorkbook.Password = ""
        objWorkbook.SaveAs("\\" + Str(Dts.Variables("User::ImportFileDir").Value) + "\" + Str(Dts.Variables("User::ImportFileDir").Value) + ".xls")

        objExcel.Quit()
0
Comment
Question by:aneilg
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
wshark83 earned 500 total points
ID: 37724809
how about this:

Sub showdate()

Dim sdate As String
        sdate = Right("00" & Year(Now()), 4) & Right("0" & Month(Now()), 2) & Right("00" & Day(Now()), 2)
               
        MsgBox "date " & sdate
End Sub
0
 

Author Comment

by:aneilg
ID: 37724922
perfect, thanks.
0
 

Author Closing Comment

by:aneilg
ID: 37724927
perfect, thanks.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

815 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

8 Experts available now in Live!

Get 1:1 Help Now