LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Do While only does once

I'm having trouble getting a do loop to advance. I'm used to working
with for next loops, and this one is new to me. I'm trying to cycle
through files in a folder, look their names up in a table, find a new
name, and rename the file. This code works on the first iteration, and
then errors out the second time through on the Name line, with a type
mismatch. Any suggestions would be greatly appreciated. THANKS.


Dim OldName As String
Dim NewName As String
Dim File
Dim myPath As String

myPath = ActiveWorkbook.Path
File = Dir(myPath & "\*.WMV")

Do While File < ""
'Application.StatusBar = "Renaming files."
If File < ThisWorkbook.Name Then
OldName = File
' MsgBox OldName
' MsgBox NewName

NewName = Application.VLookup(OldName, Range("sortdata"), 4,
False)

POldName = myPath & "\" & OldName
PNewName = myPath & "\" & NewName

MsgBox POldName
MsgBox PNewName

Name POldName As PNewName
' OldName = ""
' NewName = ""
End If
'Exit Sub
Loop
 
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



All times are GMT +1. The time now is 02:24 AM.

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

About Us

"It's about Microsoft Excel"