Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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)

share|improve this question

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
share|improve this answer
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. – name_masked Mar 11 '13 at 18:50
You're welcome. I don't know much about Excel Tags, sorry. – Desmond Hume Mar 11 '13 at 18:59

You must log in to answer this question.

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