Macros - Excel

Hi,

I have made a macro for a project which i am working on. I have to run this macro every week on different files. These files have names which include the date of the data. Now without overwriting this file i want to run the macro but want the date of this file to be included in the final file which i have made. Is there anyway to do this

for eg: Data file : Name : ABC 10-3-06

i want the final output files name to be : XYZ 10-3-06

Can somebody please help me.

Aziz.



Answer this question

Macros - Excel

  • Fiumag

    Aziz - you could use the Split function to parse the filename and get the date.

    To continue Derek's example:

    Dim x() as String
    Dim strDate as String

    sFile = fs.GetFileName("C:\ABC 10-3-06")

    x = Split(sFile, " ") 'get array of substrings - delimiter is space character
    strDate = x(UBound(x)) 'date is last element in array

    and continue...

  • maara

    Moving this post to the Visual Basic for Applications forum.

  • programmerInprogress

    Hi Aziz,

    This will be no problem. Look at the FileSystemObject in the help file, it contains objects like file and directory that you use to create and rename files. So for example you can get the file name of ABC 10-3-06 as a string and parse the date from it. Once you've got that you can use it to your hearts content with other file names.

    A short example would be something like this....

    Set fs = CreateObject("Scripting.FileSystemObject")
    Dim sFile as string

    sFile = fs.GetFileName(C:\ABC 10-03-06) 'get the file name to parse

    Definately look in the help files or online for information on the FileSystemObject as its a power and useful file IO object.

    The tricky bit is parsing the date out of the filename as that will depend on how consisitant the files have been named.



  • Macros - Excel