J
Joanne Buss
Good Morning All
I am using WinXP Pro SP3 with MSOffice 2003 on Dell Optiplex GX270
I am using the following code to check and see if a file I am renaming
already exists in the folder. An MVP helped me with this code 3-4 years ago
and while it works just great there is one little thing I would like to
tweak, but I just don't know how to. I am hoping someone here will help me.
Example - when I rename a file jones-r.txt and the code looks in the
directory for it, if it finds, say, jones-re.txt, it thinks it is the same
file and will ask me if I want to overwrite it. For some reason, it seems to
look only at the first letter after the dash, never seeing the second
letter. I would like it to see the second letter and only ask if I want to
overwrite if I have really given the file the exact same name.
Here is the Code:
NameReplace = InputBox(Message, Title, Default, 5500, 5500) 'Sets msg box
and its placement on the screen
ChangeFileOpenDirectory "h:\done"
Dim strMsg As String ' Message to return if file exists
strMsg = "Do you want to replace the existing " & NameReplace & "?"
' Check if the file exists.
If Dir(NameReplace & "*") = "" Then
' If file does not exist, save without prompting.
ActiveDocument.SaveAs FileName:=NameReplace, FileFormat:=wdFormatText
ActiveDocument.Close
Else
'If file does exist, prompt with warning message.
' Check value of button clicked in message box.
Select Case MsgBox(strMsg, vbYesNoCancel)
Case vbYes
' If Yes was chosen, save and overwrite existing file.
ActiveDocument.SaveAs FileName:=NameReplace,
FileFormat:=wdFormatText
ActiveDocument.Close
Case vbNo
Dim strMsg2 As String ' Message to return if file exists
strMsg2 = "What name do you want to use?"
NameReplace = InputBox(Message, Title, Default, 5500, 5500) 'Sets
msg box and its placement on the screen
ActiveDocument.SaveAs FileName:=NameReplace,
FileFormat:=wdFormatText
ActiveDocument.Close
Case vbCancel
' If Cancel is chosen, close document
ActiveDocument.Close
End Select
End If
Any enlightenment would be greatly appreciated. I have gotten the question
of this lodged in my head and am really hungry for the answer, like working
a puzzle and looking for the very last answer I guess.
Thank you so much
Joanne
I am using WinXP Pro SP3 with MSOffice 2003 on Dell Optiplex GX270
I am using the following code to check and see if a file I am renaming
already exists in the folder. An MVP helped me with this code 3-4 years ago
and while it works just great there is one little thing I would like to
tweak, but I just don't know how to. I am hoping someone here will help me.
Example - when I rename a file jones-r.txt and the code looks in the
directory for it, if it finds, say, jones-re.txt, it thinks it is the same
file and will ask me if I want to overwrite it. For some reason, it seems to
look only at the first letter after the dash, never seeing the second
letter. I would like it to see the second letter and only ask if I want to
overwrite if I have really given the file the exact same name.
Here is the Code:
NameReplace = InputBox(Message, Title, Default, 5500, 5500) 'Sets msg box
and its placement on the screen
ChangeFileOpenDirectory "h:\done"
Dim strMsg As String ' Message to return if file exists
strMsg = "Do you want to replace the existing " & NameReplace & "?"
' Check if the file exists.
If Dir(NameReplace & "*") = "" Then
' If file does not exist, save without prompting.
ActiveDocument.SaveAs FileName:=NameReplace, FileFormat:=wdFormatText
ActiveDocument.Close
Else
'If file does exist, prompt with warning message.
' Check value of button clicked in message box.
Select Case MsgBox(strMsg, vbYesNoCancel)
Case vbYes
' If Yes was chosen, save and overwrite existing file.
ActiveDocument.SaveAs FileName:=NameReplace,
FileFormat:=wdFormatText
ActiveDocument.Close
Case vbNo
Dim strMsg2 As String ' Message to return if file exists
strMsg2 = "What name do you want to use?"
NameReplace = InputBox(Message, Title, Default, 5500, 5500) 'Sets
msg box and its placement on the screen
ActiveDocument.SaveAs FileName:=NameReplace,
FileFormat:=wdFormatText
ActiveDocument.Close
Case vbCancel
' If Cancel is chosen, close document
ActiveDocument.Close
End Select
End If
Any enlightenment would be greatly appreciated. I have gotten the question
of this lodged in my head and am really hungry for the answer, like working
a puzzle and looking for the very last answer I guess.
Thank you so much
Joanne