Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Name x as y Deletes file
Thanks for taking the time to read my question
Name ReNamestrFileName As Right(ReNamestrFileName, 4) & "1.jpg" The line above seems to delete my files. I don't know why, and wish it wouldn't. Any ideas on what I am doing wrong? If this would work, my function would be perfect My function is supposed to change files names *.JPG to *.jpg Thanks, Brad Function below --------------------------------- Function ImageNameDoc() Dim strFileName, ReNamestrFileName As String On Error GoTo ImageNameDoc_Err: strFileName = Dir("C:\LNUPictures\Images\*.jpg") ReNamestrFileName = "C:\LNUPictures\Images\" & strFileName Open "C:\LNUPictures\ImageNames.txt" For Output As #1 Do While strFileName < "" 'Rename to .jpg from .JPG If Right(strFileName, 4) = ".JPG" Then Name ReNamestrFileName As Right(ReNamestrFileName, 4) & "1.jpg" FileCopy Right(ReNamestrFileName, 4) & ".jpg", Right(ReNamestrFileName, 4) & ".jpg" Kill Right(ReNamestrFileName, 4) & "1.jpg" End If If Right(strFileName, 8) = "zoom.jpg" Then Print #1, strFileName End If If UserForm1.ProgressBar1.Value + Yb < 100 Then UserForm1.ProgressBar1 = UserForm1.ProgressBar1 + Yb Else UserForm1.ProgressBar1 = 100 End If strFileName = Dir ReNamestrFileName = "C:\LNUPictures\Images\" & strFileName Loop Close #1 ImageNameDoc_Exit: Exit Function ImageNameDoc_Err: MsgBox Err.Number & ", " & Err.Description Close #1 End Function |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Name x as y Deletes file
The problem was not with Name but rather with my Right() statement. That was
the wrong one. This code works, Brad Function ImageNameDoc() Dim strFileName, ReNamestrFileName, NameFrom, NameTo, NameNew As String On Error GoTo ImageNameDoc_Err: 'strFileName = Dir("O:\LNUPictures\Images\*.jpg") strFileName = Dir("C:\LNUPictures\Images\*.jpg") ReNamestrFileName = "C:\LNUPictures\Images\" & strFileName 'Open "O:\LNUPictures\ImageNames.txt" For Output As #1 Open "C:\LNUPictures\ImageNames.txt" For Output As #1 Do While strFileName < "" 'Rename to .jpg from .JPG If Right(strFileName, 4) = ".JPG" Then NameFrom = Left(ReNamestrFileName, Len(ReNamestrFileName) - 4) & ".JPG" 'Right(ReNamestrFileName, 4) & ".JPG" NameTo = Left(ReNamestrFileName, Len(ReNamestrFileName) - 4) & ".jpg" 'Right(ReNamestrFileName, 4) & "1.jpg" Name NameFrom As NameTo End If If Right(strFileName, 8) = "zoom.jpg" Then Print #1, strFileName End If If UserForm1.ProgressBar1.Value + Yb < 100 Then UserForm1.ProgressBar1 = UserForm1.ProgressBar1 + Yb Else UserForm1.ProgressBar1 = 100 End If strFileName = Dir ReNamestrFileName = "C:\LNUPictures\Images\" & strFileName Loop Close #1 ImageNameDoc_Exit: Exit Function ImageNameDoc_Err: MsgBox Err.Number & ", " & Err.Description Close #1 End Function "Brad" wrote: Thanks for taking the time to read my question Name ReNamestrFileName As Right(ReNamestrFileName, 4) & "1.jpg" The line above seems to delete my files. I don't know why, and wish it wouldn't. Any ideas on what I am doing wrong? If this would work, my function would be perfect My function is supposed to change files names *.JPG to *.jpg Thanks, Brad Function below --------------------------------- Function ImageNameDoc() Dim strFileName, ReNamestrFileName As String On Error GoTo ImageNameDoc_Err: strFileName = Dir("C:\LNUPictures\Images\*.jpg") ReNamestrFileName = "C:\LNUPictures\Images\" & strFileName Open "C:\LNUPictures\ImageNames.txt" For Output As #1 Do While strFileName < "" 'Rename to .jpg from .JPG If Right(strFileName, 4) = ".JPG" Then Name ReNamestrFileName As Right(ReNamestrFileName, 4) & "1.jpg" FileCopy Right(ReNamestrFileName, 4) & ".jpg", Right(ReNamestrFileName, 4) & ".jpg" Kill Right(ReNamestrFileName, 4) & "1.jpg" End If If Right(strFileName, 8) = "zoom.jpg" Then Print #1, strFileName End If If UserForm1.ProgressBar1.Value + Yb < 100 Then UserForm1.ProgressBar1 = UserForm1.ProgressBar1 + Yb Else UserForm1.ProgressBar1 = 100 End If strFileName = Dir ReNamestrFileName = "C:\LNUPictures\Images\" & strFileName Loop Close #1 ImageNameDoc_Exit: Exit Function ImageNameDoc_Err: MsgBox Err.Number & ", " & Err.Description Close #1 End Function |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
shared file adds or deletes rows | Excel Discussion (Misc queries) | |||
Macro that deletes every third row....+ | Excel Discussion (Misc queries) | |||
Detecting when a user deletes a row | Excel Programming | |||
Repetative Row Deletes | Excel Discussion (Misc queries) | |||
Excel renaming file to a temp and deletes original (long) | Excel Programming |