Consulting

Results 1 to 2 of 2

Thread: Use VBA to save a document including a word from within the file in the filename

  1. #1
    VBAX Regular
    Joined
    Jul 2010
    Location
    London, near Heathrow
    Posts
    9
    Location

    Use VBA to save a document including a word from within the file in the filename

    Hi everyone. I have a document which I have split into single page documents. Hoever, when each single page document is saved, I would like to save the document as "Diagram xxx". The format of the document means that the xxx is always the 6th word and is as follows: Transport Company Anytown LTP MB xxx The space between LTP and MB is one Tab as is the space between MB and xxx. Thanks for in advance.

  2. #2
    Without knowing how the pages are separated it is difficult to produce a loop that will loop through the pages. However given your description the folllowing will find the wanted xxx strings in the document, which should help you on your way.

    If this is the result of a mail merge you might find http://www.gmayor.com/MergeAndSplit.htm useful

    Dim oRng As Range
    Dim sName As String
        Set oRng = ActiveDocument.Range
        With oRng.Find
            Do While .Execute(FindText:="Transport Company Anytown LTP" & Chr(9) & "MB" & Chr(9))
                sName = "Diagram "
                oRng.Collapse 0
                oRng.MoveEnd wdWord
                sName = sName & oRng.Text
                MsgBox sName
                oRng.Collapse 0
            Loop
        End With
    Graham Mayor - MS MVP (Word)
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •