Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 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
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. –  darkie15 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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.