Re: Do While only does once
From: Bob Phillips (bob.phillips_at_notheretiscali.co.uk)
Date: 04/08/04
- Next message: Doug Van: "Re: UPDATE & COMPARE"
- Previous message: Brad E: "Pop-up Combo Box"
- In reply to: Mike Williams: "Do While only does once"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 8 Apr 2004 16:05:15 +0100
Hi Mike,
I think it errors because you are not changing File in the loop, so each
iteration is using the same value. But as it got changed in iteration 1,
trying to rename it again in loop 2 throws the error, it doesn't exist by
that name then.
--
HTH
Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
"Mike Williams" <williamsmi@simon.rochester.edu> wrote in message
news:Xns94C56B4EDCB81MikeWill2@207.46.248.16...
> 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
- Next message: Doug Van: "Re: UPDATE & COMPARE"
- Previous message: Brad E: "Pop-up Combo Box"
- In reply to: Mike Williams: "Do While only does once"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|