?
Solved

Add a Date to a File Name.

Posted on 2012-03-15
3
Medium Priority
?
246 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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

752 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