Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-11-2012, 03:33 AM
gsrikanth gsrikanth is offline Rename Files Windows XP Rename Files Office XP
Competent Performer
Rename Files
 
Join Date: Dec 2011
Posts: 133
gsrikanth is on a distinguished road
Default Rename Files

if i want to give in excel existing file name in the folder replace to beside column name for example

excel data (12 names and 12 names with code)

MUDHOJIWADI
RADHAIPALLE
KANNAPUR
MODEGAON
MOSHAMPUR
PALVANCHA
TIPPAPUR
YELLAPGONDA
WADI
AKKAPUR
AMARLABADA


LINGAMPALLE
BANAPUR
MOMBAJIPET
MANGARAM
GADKOLE
KONDUR
PAKHAL

AP18025024 MUDHOJIWADI
AP18025011 RADHAIPALLE
AP18025016 KANNAPUR
AP18025025 MODEGAON
AP18025019 MOSHAMPUR
AP18024016 PALVANCHA
AP18035006 TIPPAPUR
AP18024018 YELLAPGONDA
AP18024020 WADI
AP18024008 AKKAPUR
AP18025028 AMARLABADA
AP18025026 LINGAMPALLE
AP18032004 BANAPUR
AP18032003 MOMBAJIPET
AP18032016 MANGARAM
AP18023018 GADKOLE
AP18023012 KONDUR
AP18023020 PAKHAL

Last edited by macropod; 05-11-2012 at 03:36 AM. Reason: Excel topic wrongly posted in Word vba thread
Reply With Quote
  #2  
Old 05-11-2012, 08:15 PM
macropod's Avatar
macropod macropod is offline Rename Files Windows 7 64bit Rename Files Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi,

You can use code like the following. I've assumed the names are in your workbook. If they're not, you can modify the code to suit - the basic principles are the same. Note that the Filepath must end with a "\"
Code:
Sub RenameFiles()
Dim i As Long, Strpath As String
Strpath = "Filepath"
With ActiveSheet
  On Error Resume Next
  For i = 1 To 12
    If Dir(Strpath & .Cells(i, 2).Value, vbNormal) <> "" Then
      Name Strpath & .Cells(i, 2).Value As Strpath & .Cells(i, 1).Value & .Cells(i, 2).Value
    End If
  Next
End With
End Sub
PS: Please don't post Excel vba questions in the Word vba forum.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 05-14-2012, 02:15 AM
gsrikanth gsrikanth is offline Rename Files Windows XP Rename Files Office XP
Competent Performer
Rename Files
 
Join Date: Dec 2011
Posts: 133
gsrikanth is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Hi,

You can use code like the following. I've assumed the names are in your workbook. If they're not, you can modify the code to suit - the basic principles are the same. Note that the Filepath must end with a "\"
Code:
Sub RenameFiles()
Dim i As Long, Strpath As String
Strpath = "Filepath"
With ActiveSheet
  On Error Resume Next
  For i = 1 To 12
    If Dir(Strpath & .Cells(i, 2).Value, vbNormal) <> "" Then
      Name Strpath & .Cells(i, 2).Value As Strpath & .Cells(i, 1).Value & .Cells(i, 2).Value
    End If
  Next
End With
End Sub
PS: Please don't post Excel vba questions in the Word vba forum.
in Filepath place in kept my path "\\geodb-1\f\villages\"
i have folder that
excel i kept attachment

using above code no replace occur
Attached Files
File Type: xlsx Book20.xlsx (10.6 KB, 8 views)
Reply With Quote
  #4  
Old 05-14-2012, 03:03 AM
macropod's Avatar
macropod macropod is offline Rename Files Windows 7 64bit Rename Files Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

It would have been easier if you had posted a workbook with sample data to begin with.

Try:
Code:
Sub RenameFiles()
Dim i As Long, Strpath As String
Strpath = "\\geodb-1\f\villages\"
With ActiveSheet
  On Error Resume Next
  For i = 1 To 12
    If Dir(Strpath & .Cells(i, 1).Value, vbNormal) <> "" Then
      Name Strpath & .Cells(i, 1).Value As Strpath & .Cells(i, 2).Value
    End If
  Next
End With
End Sub
Note: you may still have to change Strpath to use a conventional filepath, rather than the network path.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Rename a Quick Part sleake Word 14 10-14-2013 09:21 AM
Can't rename shared calendars kenelder Outlook 0 06-02-2011 07:53 AM
Rename Files Rename File cksm4 Word VBA 2 02-25-2011 09:29 AM
Rename Files Rename Outlook 2003 Contacts Folder sfpermits Outlook 6 07-21-2010 09:56 AM
Rename Files code to save / rename / send attachments unit213 Outlook 1 09-26-2007 08:15 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:15 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft