Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default 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
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
shared file adds or deletes rows woodman Excel Discussion (Misc queries) 0 May 31st 07 04:46 PM
Macro that deletes every third row....+ ajjag Excel Discussion (Misc queries) 4 June 27th 06 06:03 PM
Detecting when a user deletes a row Wescotte Excel Programming 7 January 18th 06 04:26 PM
Repetative Row Deletes scratching my head Excel Discussion (Misc queries) 1 May 30th 05 09:38 PM
Excel renaming file to a temp and deletes original (long) John Excel Programming 1 June 16th 04 08:57 PM


All times are GMT +1. The time now is 07:40 PM.

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"