Solved

Add a Date to a File Name.

Posted on 2012-03-15
3
243 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

730 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