0

We have a bunch of Excel documents which gets tossed around a lot. Every time somebody makes a copy of a file, in windows it gets generated as 'Copy of - <filename>.xlsm'. We would like to extract the filename of each file it was assigned originally/first time i.e. get '<filename.txt>' instead of 'Copy of - <filename>.xlsm'.

I tried looking at the file properties such as Tag, but these fields have not been set for some of the files already distributed. Is it possible to extract the filename of a file that originally assigned? (using VBA or Powershell scripting)

1 Answer 1

1

Try this after you assign a filename to filename variable in VBA

Dim origFilename As String
origFilename = filename
If Left(filename, 10) = "Copy of - " Then
    origFilename = Replace(filename, "Copy of - ", "")
End If
2
  • thanks for the answer. But I was hoping if it was a case where the excel documents stored some metadata of this information. It can be possible that the end user renames a file as <filename>_2.xlsm. The closest (being a non VBA coder) I could think of achieving this is using Tag property in Excel as means to get the original filename. Mar 11, 2013 at 18:50
  • You're welcome. I don't know much about Excel Tags, sorry. Mar 11, 2013 at 18:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .