I'm a little new to VB and am mostly self-taught, as such my code is probably very inefficient and not done properly: Anyway, to my question, can someone tell me why the following code tells me that the "Name" line gives an Invalid procedure call or argument (Error 5). If I write a test code which does essentially the same thing (without all the search and automation) it works fine... why does the same command in two contexts not work the same?
Code that won't work:
VB Code:
Sub PicRename() Dim day As String day = InputBox("Please enter the folder name as it appears in my pics") Dim hour As Integer hour = InputBox("Please enter the latest hour (after midnight - on a 24h clock) for pictures to be converted") Dim num As Integer num = 0 Dim newnum As Integer Dim changer As String Dim newnam As String alpha: newnum = num + 24 With Application.FileSearch .FileName = "0" & num & "????AA.JPG" .LookIn = "C:\Documents and Settings\PCPC\My Documents\My Pictures\" & day & "\" .Execute If .FoundFiles.Count = 0 Then GoTo Omega For i = 1 To 1 changer = .FoundFiles(i) With Selection .TypeText (changer) .MoveLeft unit:=wdCharacter, Count:=10, Extend:=wdMove .MoveLeft unit:=wdCharacter, Count:=2, Extend:=wdExtend .TypeText (newnum) .HomeKey unit:=wdStory, Extend:=wdMove .EndKey unit:=wdStory, Extend:=wdExtend newnam = .Text .Delete End With Next i End With 'line that doesn't work: Name changer As newnam GoTo alpha: Omega: If num < hour Then num = num + 1 GoTo alpha: End If End Sub
Code that does work:
VB Code:
Sub Test() Dim changer As String Dim newnam As String changer = "C:\Documents and Settings\PCPC\My Documents\My Pictures\2005_1224\005206AA.JPG" newnam = "C:\Documents and Settings\PCPC\My Documents\My Pictures\2005_1224\245206AA.JPG" Name changer As newnam End Sub
If anyone could help me figure this out it would be greatly appreciated.


Reply With Quote
