Re: Renaming documents from text within the document using existin

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Success! The problem was in the original document. After the person's name
there was a tab and then more information. I didn't realize that Word would
cound Tab and Enter as a character rather than a series of blank spaces. I
changed the original document so that after the person's name is on a line by
itself and use the space bar to give me extra space to account for people
with really long names.

This is going to save me so much time. Thanks for your help.

"Steve Yandl" wrote:

Are there any characters appearing on line one beside "Name:" and the name
of a person? Some characters would not be allowed as part of the file name.
Try changing the "6" to "7" so you have
strName = RTrim(ActiveDocument.Range(7, 50).Text)
and see if that works.

Steve

"Suzanne C" <SuzanneC@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:C825A82B-8AB7-485D-B126-342C59C36976@xxxxxxxxxxxxxxxx
That makes sense :) Unfortunately it still doesn't work. I get an error
stating that it is not a valid file name.

"Steve Yandl" wrote:

Suzanne,

Don't put the quote marks around strName. It's a variable that
represents
the name extracted from line 1.

Steve



"Suzanne C" <SuzanneC@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:6F37A59F-7BF6-4472-84A0-ED6B93BA8A2D@xxxxxxxxxxxxxxxx
I had to alter it to:
strName = RTrim(ActiveDocument.Range(6, 50).Text)
ActiveDocument.SaveAs FileName:="strName" & ".doc",

but the only thing this did was save one document as strName.doc.

"Steve Yandl" wrote:

Suzanne,

I wasn't sure if you wanted to simply save the document with the name
found
or also have the numbering you show in your sub. Try something like:

strName = RTrim(ActiveDocument.Range(6, 50).Text)
ActiveDocument.SaveAs FileName:="C:\Test\" & strName & ".doc"

Steve


"Suzanne C" <SuzanneC@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:40334E96-56B5-4B4A-B998-25EF64DEC17B@xxxxxxxxxxxxxxxx
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









.



Relevant Pages