Make a new doc and copy/paste contents from/ between to bookmarks

W

Wespa

Hi!
Aim looking for some code what could help me with following.
Word 2003 prof.
I want to creat a new document, copy contents between to bookmarks from an
active document and paste it to the new document
 
H

Helmut Weber

Hi,
like this, to get you going:
Sub Test351()
Dim r As Range
Set r = Selection.Range
With ActiveDocument.Range
r.start = .Bookmarks("Marke1").Range.End
r.End = .Bookmarks("Marke2").Range.start
End With
Documents.Add
ActiveDocument.Range.FormattedText = r.FormattedText
End Sub
---
But there are many ways of improvement, e.g.
the activedocument changes from the document
containing the bookmarks to the new document.
Better avoid it. Would you like to know how?
What template would you like the new document
to be created from? Would that contain anything?
If so, where in the new doc should the text appear?
Problems may arise with the formatting of the
transfered text, if the formatting is not direct
formatting, but based on styles.
Want to know more, ask again.
 
W

Wespa

Hi,
i'm using several bookmarks in the original document and the contents
between each of the bookmarks are to bee tranfered to multiple new documents .

"Helmut Weber" skrev:
 
H

Helmut Weber

Hi,
then it is getting not more complicated, but tedious.
Like the following, which has a lot of undesirable repetitions.
These could be avoided by creating arrays of documents,
arrays of bookmarks, arrays of ranges. If there are rules,
which range of the primary document goes to where in which
other document, then all you got to do, is put this algorithm
down in code, though easier said than done. Unless so, you have
to write down one after another, which range goes to what document
and where.
I am hoping, the principle will clear and be helpful.
---
Sub test444()
Dim oDcm00 As Document
Dim oDcm01 As Document
Dim oDcm02 As Document
Dim oDcm03 As Document
Dim r1 As Range
Dim r2 As Range
Dim r3 As Range
ActiveDocument.SaveAs "c:\test\test-00.doc"
Set oDcm00 = Documents("test-00.doc")
Set oDcm01 = Documents.Add(Visible:=False)
oDcm01.SaveAs "c:\test\test-01.doc"
Set oDcm02 = Documents.Add(Visible:=False)
oDcm02.SaveAs "c:\test\test-02.doc"
Set oDcm03 = Documents.Add(Visible:=False)
oDcm03.SaveAs "c:\test\test-03.doc"
With oDcm00
Set r1 = .Range
r1.start = .Bookmarks("M1").End
r1.End = .Bookmarks("M2").start
Set r2 = .Range
r2.start = .Bookmarks("M3").End
r2.End = .Bookmarks("M4").start
Set r3 = .Range
r3.start = .Bookmarks("M5").End
r3.End = .Bookmarks("M6").start
End With
oDcm01.Range.Text = r1.Text
oDcm01.Save
oDcm02.Range.Text = r2.Text
oDcm02.Save
oDcm03.Range.Text = r3.Text
oDcm03.Save
oDcm01.Close
oDcm02.Close
oDcm03.Close
Set oDcm01 = Nothing
Set oDcm02 = Nothing
Set oDcm03 = Nothing
End Sub
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
W

Wespa

Hi
Thanks. but i've some problem with the format.
In the original dokument theres numberlist items .
I tried to change the code below to .words
intsted of Text, but it didnt work.

oDcm01.Range.Text = r1.Text

any tip

"Helmut Weber" skrev:
 
H

Helmut Weber

Hi Wespa,
though it may be possible, I would not try this approach.
Transferring automatically numbered lists
requires transfering their paragraph marks also.
But their is more to it. You would have to find out,
where in the whole list the paragraph is placed.
If you transfer a listparagraph
and only this listparagraph, which may have number 2,
to a new document, it gets number 1 !!!
Stay away from this!
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 

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