Thread: [Solved] Rename Document & Save
View Single Post
 
Old 05-22-2013, 10:49 PM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
Code:
Sub ReSave()
Dim StrName As String, StrExt As String, StrNum As String, Rslt
With ActiveDocument
  StrName = .Name
  StrExt = Right(StrName, Len(StrName) - InStrRev(StrName, ".") + 1)
  StrName = Left(StrName, InStrRev(StrName, ".") - 1)
  StrNum = Format(Split(StrName, " ")(UBound(Split(StrName, " "))) + 1, "00")
  StrName = Left(StrName, InStrRev(StrName, " "))
  StrName = .Path & "\" & StrName & StrNum & StrExt
  If Dir(StrName) <> "" Then
    Beep
    Rslt = MsgBox("The new filename:" & vbCr & StrName & vbCr & "already exists." & _
      vbCr & "Continue saving (overwrite existing file)?", vbOKCancel)
    If Rslt = vbCancel Then Exit Sub
  End If
  .SaveAs2 FileName:=StrName, FileFormat:=.SaveFormat
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]

Last edited by macropod; 05-22-2013 at 11:06 PM. Reason: Added warning code
Reply With Quote