Did you really mean "prefix"? Prefix means "in front of" so if you meant prefix, then you have the space on the wrong side of the word "Sales". Or did you mean "suffix" (meaning "after")? If one of your filenames was "Account.xls", did you want "Sale Account.xls" or "Account Sales.xls"?I have some files in this directory
C:\Users\m_aatif\Desktop\Test\
I want each file name to have a prefix " Sales" and then contain the existing name. How can I add this prefix to all files?
Give this macro a try...Suppose my file name is at the moment "Forecast europe", I want it to be replaced with "Sales Forecast europe".
Sub AddSalesPrefix()
Dim Path As String, Filename As String
Path = "c:\Users\m_aatif\Desktop\Test\"
Filename = Dir(Path & "*", vbNormal)
Do While Len(Filename)
Name Path & Filename As Path & "Sales " & Filename
Filename = Dir()
Loop
End Sub
Give this macro a try...
Code:Sub AddSalesPrefix() Dim Path As String, Filename As String Path = "c:\Users\m_aatif\Desktop\Test\" Filename = Dir(Path & "*", vbNormal) Do While Len(Filename) Name Path & Filename As Path & "Sales " & Filename Filename = Dir() Loop End Sub
I tried the same buy I m getting result like;
sales sales sales sales ... many times and then filename.
Dear SirGive this macro a try...
Code:Sub AddSalesPrefix() Dim Path As String, Filename As String Path = "c:\Users\m_aatif\Desktop\Test\" Filename = Dir(Path & "*", vbNormal) Do While Len(Filename) Name Path & Filename As Path & "Sales " & Filename Filename = Dir() Loop End Sub