1

I have a text file called SampleTestFile.ghi. After this file is processed by a program, it is renamed and moved into another folder. The naming convention used when renaming the file is *.abc

So I have the file name (SampleTestfile.ghi), I have the naming convention (*.abc), but how can I convert the original file name into the processed filename using VBA? Is there a way I can say

ProcessFileName = "SampleTestFile.ghi" & "*.abc" 
''and get the correct answer of SampleTestFile.abc ?
TylerDurden
  • 1,632
  • 1
  • 20
  • 30
user3046742
  • 235
  • 1
  • 11
  • Okay which program is processing the file? How do you know that the file was processed? Based on your file extension it doesnt look like a Microsoft Office file. I think a better option for you, would be to move all the processed files into one folder, and a run a batch script file to rename all processed files in the folder. Check this, http://stackoverflow.com/questions/16162103/batch-file-to-rename-files-in-multiple-folders – Jeanno Jan 19 '15 at 17:54
  • is the `.abc` a FILE EXTENSION or part of the FILE NAME? – Chrismas007 Jan 19 '15 at 17:55

1 Answers1

1
ProcessFileName = Replace(sampleTestFileName, ".ghi",".abc")

Assuming ".ghi" never occurs in the middle of the filename

Probably safer to use Mid()

Sub Test()

    Dim s
    s = "my strange filename.ghi here.ghi"

    Debug.Print "original", s

    'Method 1 (has a potential problem)
    Debug.Print "method 1", Replace(s, ".ghi", ".abc")

    'Method 2 (safer)
    Mid(s, Len(s) - 3, 4) = ".abc"
    Debug.Print "method 2", s

End Sub
Tim Williams
  • 154,628
  • 8
  • 97
  • 125
  • That gives me an idea. I can just replace the * wildcard in the processed file naming convention with the original file name. Thanks! – user3046742 Jan 19 '15 at 19:42