Solved

Add a Date to a File Name.

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

757 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

21 Experts available now in Live!

Get 1:1 Help Now