VBA code to add a prefix in all files in a folder

m_aatif

Board Regular
Joined
Apr 18, 2013
Messages
56
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?

Regards
Atif
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
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?
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"?
 
Upvote 0
Suppose my file name is at the moment "Forecast europe", I want it to be replaced with "Sales Forecast europe".
 
Upvote 0
Suppose my file name is at the moment "Forecast europe", I want it to be replaced with "Sales Forecast europe".
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
 
Upvote 0
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

Rick, thanks for the code!
 
Upvote 0
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
Dear Sir
I request you to help me to prefix serial numbers to files in a folder like below:
001. File A
002. File B
003. File C
Regardas

Thanks in advance

Buvanamali
 
Upvote 0

Forum statistics

Threads
1,215,028
Messages
6,122,749
Members
449,094
Latest member
dsharae57

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top