Results 1 to 2 of 2

Find and replace string in file name

Threaded View

  1. #1
    Registered User
    Join Date
    11-24-2015
    Location
    New Zealand
    MS-Off Ver
    2021 Professional plus
    Posts
    10

    Angry Find and replace string in file name

    Good evening all from NZ.

    I have about 30 files to copy to a new folder & rename the files with the date format ddmmyyyy added at the end of the filename before the Ext identifier ie
    filename.doc? to filename ddmmyyyy.doc? (I also need to modify actual files and want to do this via a macro iteration but one step at a time.

    This project will be on going and having to do this 2 or 3 times a week. There are also repetitive tasks that need to happen within the files that need opening up, changing and saving. But one step at a time.

    Here is a sample of an actual file name change
    1.2 Annual Objectives.doc to 1.2 Annual Objectives ddmmyyyy.doc

    I have 2 problems - the first is most files start with the numbering 1.4 Name*.*x
    That is there is a "." in the 2nd position of the filename.

    The other problem that I have varierty of filetypes xls, xlsx, doc, docx, pdf etc

    to replace the "." with "ddmmyyyy." I have this code - (The "Find" is the problem in VBA)


     strName = Replace(Find(".", A2, 6), " " & Format(Now(), "ddmmyyyy") & ".")
    I found this code on this site which looks pretty good for what I want but I need to work out how find the location of the ext identifier and append the date to it.


    '
     Get the full name of the current attachment.
    strAtmtFullName = atmt.FileName
    
    ' Find the dot postion in atmtFullName.
    intDotPosition = InStrRev(strAtmtFullName, ".")
    
    ' Get the name.
    strAtmtName(0) = Left$(strAtmtFullName, intDotPosition - 11)
    ' Get the file extension.
    strAtmtName(1) = Right$(strAtmtFullName, Len(strAtmtFullName) - intDotPosition)
    ' Get the full saving path of the current attachment.
    strAtmtPath = strFolderPath & atmt.FileName
    What I need is code to find the ext identifier (the 2nd ".") and just before that 2nd identifier I want to insert the date in the format of ddmmyyyy.

    BTW this code came from checksamir at
    HTML Code: 
    Last edited by LionelNZ; 11-24-2015 at 05:30 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Find and replace string in VBA Sub
    By detel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-25-2015, 09:45 PM
  2. Excel VBA find and replace string in non text file and rename file
    By razzack in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-01-2013, 02:43 PM
  3. [SOLVED] Find a string by VBA Regular Expression and replace a part of that string
    By taps in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-25-2013, 11:08 AM
  4. Find/Replace Characters in a string
    By Light Pail in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-20-2010, 08:08 PM
  5. Replies: 1
    Last Post: 08-04-2009, 06:42 AM
  6. Find / Replace in a string
    By Basu in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-12-2006, 10:55 AM
  7. [SOLVED] Find and Replace in a DDE string!!!
    By Mark Dullingham in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-03-2006, 08:20 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1