Solved

Add a Date to a File Name.

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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 video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

728 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