Word VBA >> Rename word document

by arjun dutta » Tue, 10 Aug 2004 16:46:26 GMT

i have a file called "abc1.doc".. can u suggest something
that whenever i edit the file, it will automatically be
renamed as "abc2.doc" . whenever i edit +1 will be added
automatically.
eg: "abc3.doc" then "abc4.doc" etc..

i hope u understand my question.
KINDLY PLEASE REPLY TO MY EMAIL ADDRESS ALSO..
thank you
My email: XXXX@XXXXX.COM



Word VBA >> Rename word document

by Graham Mayor » Tue, 10 Aug 2004 16:59:48 GMT


I use something similar which could be set up as an autoopen macro, though I
prefer to run it manually from a toolbar button. It is based on Doug
Robbin's web page - http://word.mvps.org/FAQs/MacrosVBA/NumberDocs.htm which
will provide the background. You will need to set the path and the original
filename. Use a unique file - here c:\settings.txt - to hold the count.

Sub SaveNumberedVersion()
'Based on code by Doug Robbins
Dim strPath, strFile As String

strPath = "D:\My Documents\Test\" 'set path
strFile = "My File " 'set filename

Order = System.PrivateProfileString("C:\Settings.Txt", _
"MacroSettings", "Order")
If Order = "" Then
Order = 1
Else
Order = Order + 1
End If

System.PrivateProfileString("C:\Settings.txt", "MacroSettings", _
"Order") = Order

ActiveDocument.SaveAs FileName:=strPath & strFile & _
Format(Order, "00#")
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>









Similar Threads

1. how to rename WORD document w/o right click

Version: 2008
Operating System: Mac OS X 10.5 (Leopard)

ON the PC when I want to rename a WORD document I just find it in the listing under the file where it resides, hit the right click and I get a RENAME option ... i can't figure out how to rename a WORD document on the MAC?

2. Problem with renaming Word documents

3. renaming a file, "save as" to rename file

Version: 2008

I need to change the name of a file, and I would also like to be able to click "save as" so I could name the file as I am saving, Thanks! Pat

4. Renaming documents from text within the document using existin - Word VBA

5. Renaming documents from text within the document using existing Ma

I've been working with the following Macro to seperate a large document into 
individual documents. The Macro saves these new documents as "test_1.doc", 
"test_2.doc," etc. Everytime I run the macro, I have to then go back and 
rename all the documents manually. The first line of the document always 
begins with "Name:" and I rename the document simply by copying and pasting 
the name that follows. Is there a way to have the macro do this for me? 
Something that tells it to copy line 1 col 7-50 and paste into the FileName?

Sub BreakOnSection()
   ' Used to set criteria for moving through the document by section.
   Application.Browser.Target = wdBrowseSection

   'A mail merge document ends with a section break next page.
   'Subtracting one from the section count stop error message.
   For i = 1 To ((ActiveDocument.Sections.Count) - 1)
   
'Note: If a document does not end with a section break,
'substitute the following line of code for the one above:
'For I = 1 To ActiveDocument.Sections.Count

      'Select and copy the section text to the clipboard.
      ActiveDocument.Bookmarks("\Section").Range.Copy

      'Create a new document to paste text from clipboard.
      Documents.Add
      Selection.Paste

   ' Removes the break that is copied at the end of the section, if any.
      Selection.MoveUp Unit:=wdLine, Count:=1, Extend:=wdExtend
      Selection.Delete Unit:=wdCharacter, Count:=1
ChangeFileOpenDirectory "C:\My Documents"
      DocNum = DocNum + 1
     ActiveDocument.SaveAs FileName:="test_" & DocNum & ".doc"
     ActiveDocument.Close
      ' Move the selection to the next section in the document.
     Application.Browser.Next
   Next i
   ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub

6. Renaming a linked Word document from Access - Access Forms Programming

7. Renaming a Word document from text in controls

Access 2003/XP Pro

I'm opening a Word document, typing some text, and trying to rename it using 
text from a combo and a text box on my form. The first two steps work OK, but 
when I try to rename the document, it comes up with a message box "Object 
required ".

        Dim oWord As Object
        Dim oDoc As Object
        
        'Create the Word application object.
        Set oWord = CreateObject("Word.Application")

        'Open the sample document.
        Set oDoc = oWord.Documents.Add("C:\t2hDoc\DocBlank.doc")

        'Add text
        oWord.Selection.TypeText "Start here."

        'Save the new document
        oWord.ActiveDocument.SaveAs Filename:="t2h" & 
Me.Parent!cboDestL.Column(1).Value & Me.Parent!txtHd.Value & ".doc"
       
        oWord.Visible = True

Thanks in advance

Peter

8. Can you rename an inserted word document? - Excel Functions&Formulas