Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Renaming Files: Take 2

Sorry, I dont think I was too clear. Here's an easier explanation.

I have a folder with about 150 generic file names for ".tif" scanned images.

I have an excel sheet with 150 client names with dates and the ".tif"
extension on the end in column A and a list of the 150 generic files names
in column B.

I want a macro that will look at the rename each of those generic file names
in column B with the new one in column B.

Hope thats a little easier.

"Peter Beach" wrote in message
...
Hi Niq,

Does something like this get you started?

Sub D()
Dim sName As String
Dim Arr As Variant
Dim sNewName As String

ChDir "c:\temp"

sName = Dir("c:\temp\*.txt")
Do While Len(sName) 0
Arr = Split(sName, ".")
If UBound(Arr) = 1 Then
sNewName = Arr(0) & "XXX.txt"
' Change this obviously!
On Error GoTo NameAlreadyExists
Name sName As sNewName
On Error GoTo 0
End If
RestartPoint:
sName = Dir()
Loop
Exit Sub

NameAlreadyExists:
MsgBox "Cannot rename '" & sName & "' as '" & sNewName & "' already
exists"
Resume RestartPoint
End Sub

Obviously change the filter on the initial Dir call and the renaming

rules!

HTH

Peter Beach

"Dominique Feteau" wrote in message
...
I have a bunch of files that I get scanned and returned to me with

generic
names. I need these files renamed according to the name of the client

in
each file. What I do is go through each file, before they get scanned,

and
type out the name of each client from each file. I also get a list (in

text
form) of each scanned file inserted into the excel sheet for parity.

Is there a macro that will search for the scanned file in the

appropriate
folder according to the list in excel and rename it to client name that

I
want to change it to?

I know this is long winded but what i'm looking for a way to rename a

ton
of
files as easy and as quickly as possible.

Any help would be appreciated.

Niq






  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Renaming Files: Take 2

I found this code, but it only seems to work on excel sheets. How can I
modify it so it works on any type of file.

Public Sub ReSave()

Dim fso As Scripting.FileSystemObject
Dim fsDir As Scripting.Folder
Dim fsFile As Scripting.File

Application.DisplayAlerts = False

Set fso = New Scripting.FileSystemObject

'Change to refect correct path of source directory containing Excel files

Set fsDir = fso.GetFolder("C:\Source Directory")

For Each fsFile In fsDir.Files

Workbooks.Open Filename:= fsFile

'Use this line to save workbook with name equal to only the text in cell
"A1"
'Change Path to reflect correct save path

ActiveWorkbook.SaveAs "C:\Destination Directory\" & Range("A1").Value &
".xls"

'Use this line to save workbook with name equal to old name + text in cell
"A1"
'Change Path to reflect correct save path

ActiveWorkbook.SaveAs "C:\Destination Directory\" & _
Left(ActiveWorkbook.Name, InStr(1, ActiveWorkbook.Name, ".xls") - 1) & " " &
Range("A1").Value

Next

End Sub


"Dominique Feteau" wrote in message
...
Sorry, I dont think I was too clear. Here's an easier explanation.

I have a folder with about 150 generic file names for ".tif" scanned

images.

I have an excel sheet with 150 client names with dates and the ".tif"
extension on the end in column A and a list of the 150 generic files names
in column B.

I want a macro that will look at the rename each of those generic file

names
in column B with the new one in column B.

Hope thats a little easier.

"Peter Beach" wrote in message
...
Hi Niq,

Does something like this get you started?

Sub D()
Dim sName As String
Dim Arr As Variant
Dim sNewName As String

ChDir "c:\temp"

sName = Dir("c:\temp\*.txt")
Do While Len(sName) 0
Arr = Split(sName, ".")
If UBound(Arr) = 1 Then
sNewName = Arr(0) & "XXX.txt"
' Change this obviously!
On Error GoTo NameAlreadyExists
Name sName As sNewName
On Error GoTo 0
End If
RestartPoint:
sName = Dir()
Loop
Exit Sub

NameAlreadyExists:
MsgBox "Cannot rename '" & sName & "' as '" & sNewName & "' already
exists"
Resume RestartPoint
End Sub

Obviously change the filter on the initial Dir call and the renaming

rules!

HTH

Peter Beach

"Dominique Feteau" wrote in message
...
I have a bunch of files that I get scanned and returned to me with

generic
names. I need these files renamed according to the name of the client

in
each file. What I do is go through each file, before they get

scanned,
and
type out the name of each client from each file. I also get a list

(in
text
form) of each scanned file inserted into the excel sheet for parity.

Is there a macro that will search for the scanned file in the

appropriate
folder according to the list in excel and rename it to client name

that
I
want to change it to?

I know this is long winded but what i'm looking for a way to rename a

ton
of
files as easy and as quickly as possible.

Any help would be appreciated.

Niq








  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Renaming Files: Take 2

Sub D()
Dim sName As String
Dim sNewName As String

ChDir "c:\temp"
for each cell in Range("A1:A150")
sName = cell.offset(0,1).value
sNewName = cell.value
On Error GoTo NameAlreadyExists
Name sName As sNewName
On Error GoTo 0
Next
Exit Sub

NameAlreadyExists:
MsgBox "Cannot rename '" & sName & "' as '" & sNewName & "' already
exists"
Resume Next
End Sub

--
Regards,
Tom Ogilvy

"Dominique Feteau" wrote in message
...
Sorry, I dont think I was too clear. Here's an easier explanation.

I have a folder with about 150 generic file names for ".tif" scanned

images.

I have an excel sheet with 150 client names with dates and the ".tif"
extension on the end in column A and a list of the 150 generic files names
in column B.

I want a macro that will look at the rename each of those generic file

names
in column B with the new one in column B.

Hope thats a little easier.

"Peter Beach" wrote in message
...
Hi Niq,

Does something like this get you started?

Sub D()
Dim sName As String
Dim Arr As Variant
Dim sNewName As String

ChDir "c:\temp"

sName = Dir("c:\temp\*.txt")
Do While Len(sName) 0
Arr = Split(sName, ".")
If UBound(Arr) = 1 Then
sNewName = Arr(0) & "XXX.txt"
' Change this obviously!
On Error GoTo NameAlreadyExists
Name sName As sNewName
On Error GoTo 0
End If
RestartPoint:
sName = Dir()
Loop
Exit Sub

NameAlreadyExists:
MsgBox "Cannot rename '" & sName & "' as '" & sNewName & "' already
exists"
Resume RestartPoint
End Sub

Obviously change the filter on the initial Dir call and the renaming

rules!

HTH

Peter Beach

"Dominique Feteau" wrote in message
...
I have a bunch of files that I get scanned and returned to me with

generic
names. I need these files renamed according to the name of the client

in
each file. What I do is go through each file, before they get

scanned,
and
type out the name of each client from each file. I also get a list

(in
text
form) of each scanned file inserted into the excel sheet for parity.

Is there a macro that will search for the scanned file in the

appropriate
folder according to the list in excel and rename it to client name

that
I
want to change it to?

I know this is long winded but what i'm looking for a way to rename a

ton
of
files as easy and as quickly as possible.

Any help would be appreciated.

Niq








  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Renaming Files: Take 2

no real relation between opening a workbook and doing a saveas to rename it
and renaming an unopened .TIF file from excel. See answer to your original
post in this thread.

--
Regards,
Tom Ogilvy

"Dominique Feteau" wrote in message
...
I found this code, but it only seems to work on excel sheets. How can I
modify it so it works on any type of file.

Public Sub ReSave()

Dim fso As Scripting.FileSystemObject
Dim fsDir As Scripting.Folder
Dim fsFile As Scripting.File

Application.DisplayAlerts = False

Set fso = New Scripting.FileSystemObject

'Change to refect correct path of source directory containing Excel files

Set fsDir = fso.GetFolder("C:\Source Directory")

For Each fsFile In fsDir.Files

Workbooks.Open Filename:= fsFile

'Use this line to save workbook with name equal to only the text in cell
"A1"
'Change Path to reflect correct save path

ActiveWorkbook.SaveAs "C:\Destination Directory\" & Range("A1").Value &
".xls"

'Use this line to save workbook with name equal to old name + text in cell
"A1"
'Change Path to reflect correct save path

ActiveWorkbook.SaveAs "C:\Destination Directory\" & _
Left(ActiveWorkbook.Name, InStr(1, ActiveWorkbook.Name, ".xls") - 1) & " "

&
Range("A1").Value

Next

End Sub


"Dominique Feteau" wrote in message
...
Sorry, I dont think I was too clear. Here's an easier explanation.

I have a folder with about 150 generic file names for ".tif" scanned

images.

I have an excel sheet with 150 client names with dates and the ".tif"
extension on the end in column A and a list of the 150 generic files

names
in column B.

I want a macro that will look at the rename each of those generic file

names
in column B with the new one in column B.

Hope thats a little easier.

"Peter Beach" wrote in message
...
Hi Niq,

Does something like this get you started?

Sub D()
Dim sName As String
Dim Arr As Variant
Dim sNewName As String

ChDir "c:\temp"

sName = Dir("c:\temp\*.txt")
Do While Len(sName) 0
Arr = Split(sName, ".")
If UBound(Arr) = 1 Then
sNewName = Arr(0) & "XXX.txt"
' Change this obviously!
On Error GoTo NameAlreadyExists
Name sName As sNewName
On Error GoTo 0
End If
RestartPoint:
sName = Dir()
Loop
Exit Sub

NameAlreadyExists:
MsgBox "Cannot rename '" & sName & "' as '" & sNewName & "' already
exists"
Resume RestartPoint
End Sub

Obviously change the filter on the initial Dir call and the renaming

rules!

HTH

Peter Beach

"Dominique Feteau" wrote in message
...
I have a bunch of files that I get scanned and returned to me with

generic
names. I need these files renamed according to the name of the

client
in
each file. What I do is go through each file, before they get

scanned,
and
type out the name of each client from each file. I also get a list

(in
text
form) of each scanned file inserted into the excel sheet for parity.

Is there a macro that will search for the scanned file in the

appropriate
folder according to the list in excel and rename it to client name

that
I
want to change it to?

I know this is long winded but what i'm looking for a way to rename

a
ton
of
files as easy and as quickly as possible.

Any help would be appreciated.

Niq










  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default Renaming Files: Take 2

Thanks a million Tom. Works likes a charm. Saved me a few hours a day. I
might have to do some actual work now.

Dominique

"Tom Ogilvy" wrote in message
...
Sub D()
Dim sName As String
Dim sNewName As String

ChDir "c:\temp"
for each cell in Range("A1:A150")
sName = cell.offset(0,1).value
sNewName = cell.value
On Error GoTo NameAlreadyExists
Name sName As sNewName
On Error GoTo 0
Next
Exit Sub

NameAlreadyExists:
MsgBox "Cannot rename '" & sName & "' as '" & sNewName & "' already
exists"
Resume Next
End Sub

--
Regards,
Tom Ogilvy

"Dominique Feteau" wrote in message
...
Sorry, I dont think I was too clear. Here's an easier explanation.

I have a folder with about 150 generic file names for ".tif" scanned

images.

I have an excel sheet with 150 client names with dates and the ".tif"
extension on the end in column A and a list of the 150 generic files

names
in column B.

I want a macro that will look at the rename each of those generic file

names
in column B with the new one in column B.

Hope thats a little easier.

"Peter Beach" wrote in message
...
Hi Niq,

Does something like this get you started?

Sub D()
Dim sName As String
Dim Arr As Variant
Dim sNewName As String

ChDir "c:\temp"

sName = Dir("c:\temp\*.txt")
Do While Len(sName) 0
Arr = Split(sName, ".")
If UBound(Arr) = 1 Then
sNewName = Arr(0) & "XXX.txt"
' Change this obviously!
On Error GoTo NameAlreadyExists
Name sName As sNewName
On Error GoTo 0
End If
RestartPoint:
sName = Dir()
Loop
Exit Sub

NameAlreadyExists:
MsgBox "Cannot rename '" & sName & "' as '" & sNewName & "' already
exists"
Resume RestartPoint
End Sub

Obviously change the filter on the initial Dir call and the renaming

rules!

HTH

Peter Beach

"Dominique Feteau" wrote in message
...
I have a bunch of files that I get scanned and returned to me with

generic
names. I need these files renamed according to the name of the

client
in
each file. What I do is go through each file, before they get

scanned,
and
type out the name of each client from each file. I also get a list

(in
text
form) of each scanned file inserted into the excel sheet for parity.

Is there a macro that will search for the scanned file in the

appropriate
folder according to the list in excel and rename it to client name

that
I
want to change it to?

I know this is long winded but what i'm looking for a way to rename

a
ton
of
files as easy and as quickly as possible.

Any help would be appreciated.

Niq










Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Renaming Files w/Excel Confused VB Person Excel Discussion (Misc queries) 4 March 21st 08 09:26 AM
Renaming Files Bear Excel Discussion (Misc queries) 2 December 5th 05 09:02 PM
Renaming all files in a directory Jan Kronsell[_3_] Excel Programming 4 February 19th 04 12:33 PM
Renaming files Dana Wilson Excel Programming 2 October 29th 03 05:34 PM
Renaming Files Spammastergrand Excel Programming 5 September 19th 03 10:43 PM


All times are GMT +1. The time now is 07:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"