View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Mike Williams[_2_] Mike Williams[_2_] is offline
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