Create macro to save existing filename and increment it if duplica

  • Thread starter Rachel Jacobsen
  • Start date
R

Rachel Jacobsen

Sub test1()
'
' test1 Macro
' Macro recorded 6/6/2006 by rachel
' Sub SaveIncrementedFilename()

Dim PathAndFileName As String, n As Long

PathAndFileName = "C:\Documents and Settings\itlap\Desktop\temp"
If Dir(PathAndFileName & ".doc") = "" Then
ActiveDocument.SaveAs (PathAndFileName & ".doc")
Else
n = 1
Do While Dir(PathAndFileName & n & ".doc") <> ""
n = n + 1
Loop
ActiveDocument.SaveAs PathAndFileName & n & ".doc"
End If
ActiveDocument.Close

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top