Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
Jamie Collins Jamie Collins is offline
external usenet poster
 
Posts: 4
Default Copy formatted text but not headers/footers

I have the following VBA code to copy some text from between Word documents
(I'm familiar with VBA but not the Word object library):

Const PLACEHOLDER_TEXT As String = "||ADD TEXT HERE||"

' Copy from source to clipboard
docSource.Activate
docSource.Sections(x).Range.Copy

' Paste from clipboard to target
docTarget.Activate
Selection.Find.Execute PLACEHOLDER_TEXT, , , , , , True,
WdFindWrap.wdFindContinue
Selection.Paste

What I want is for the section's formatted text to be copied/pasted into the
existing section in the target document so that the headers/footers in the
target document are preserved.

However, what seems to be happening is that the copied text is pasted as a
new Section object including the now empty headers/footers.

In other words, I want the formatting (fonts, tables, borders, etc) from the
source document but not the headers/footers. Is this possible? Thanks
  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Jamie Collins Jamie Collins is offline
external usenet poster
 
Posts: 4
Default Copy formatted text but not headers/footers

It seems the root of the problem is that selecting the Section.Range object
included the page break.

The fix I'm going with is to move the selection end of the back until the
end character is anything other than ASCII 0012 or 0013 e.g.

Replace this:

docSource.Sections(x).Range.Copy

....with this:

docSource.Sections(x).Range.Select
Do While (Asc(Right$(Selection.Range.Text, 1)) = 12 Or
Asc(Right$(Selection.Range.Text, 1)) = 13)
docSource.Range(Selection.Start, Selection.End - 1).Select
Loop
Selection.Copy

No doubt there are betters way of doing this things than using the clipboard
and the Selection object but this will do for now

"Jamie Collins" wrote:

I have the following VBA code to copy some text from between Word documents
(I'm familiar with VBA but not the Word object library):

Const PLACEHOLDER_TEXT As String = "||ADD TEXT HERE||"

' Copy from source to clipboard
docSource.Activate
docSource.Sections(x).Range.Copy

' Paste from clipboard to target
docTarget.Activate
Selection.Find.Execute PLACEHOLDER_TEXT, , , , , , True,
WdFindWrap.wdFindContinue
Selection.Paste

What I want is for the section's formatted text to be copied/pasted into the
existing section in the target document so that the headers/footers in the
target document are preserved.

However, what seems to be happening is that the copied text is pasted as a
new Section object including the now empty headers/footers.

In other words, I want the formatting (fonts, tables, borders, etc) from the
source document but not the headers/footers. Is this possible? Thanks

  #3   Report Post  
Posted to microsoft.public.word.docmanagement
Jamie Collins Jamie Collins is offline
external usenet poster
 
Posts: 4
Default Copy formatted text but not headers/footers


It seems the root of the problem is that selecting the Section.Range object
included the page break.

The fix I'm going with is to move the selection end of the back until the
end character is anything other than ASCII 0012 or 0013 e.g.

Replace this:

docSource.Sections(x).Range.Copy

....with this:

docSource.Sections(x).Range.Select
Do While (Asc(Right$(Selection.Range.Text, 1)) = 12 Or
Asc(Right$(Selection.Range.Text, 1)) = 13)
docSource.Range(Selection.Start, Selection.End - 1).Select
Loop
Selection.Copy

No doubt there are betters way of doing this things than using the clipboard
and the Selection object but this will do for now

"Jamie Collins" wrote:

I have the following VBA code to copy some text from between Word documents
(I'm familiar with VBA but not the Word object library):

Const PLACEHOLDER_TEXT As String = "||ADD TEXT HERE||"

' Copy from source to clipboard
docSource.Activate
docSource.Sections(x).Range.Copy

' Paste from clipboard to target
docTarget.Activate
Selection.Find.Execute PLACEHOLDER_TEXT, , , , , , True,
WdFindWrap.wdFindContinue
Selection.Paste

What I want is for the section's formatted text to be copied/pasted into the
existing section in the target document so that the headers/footers in the
target document are preserved.

However, what seems to be happening is that the copied text is pasted as a
new Section object including the now empty headers/footers.

In other words, I want the formatting (fonts, tables, borders, etc) from the
source document but not the headers/footers. Is this possible? Thanks

Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I copy entire pages including Headers and Footers rfdsmith Microsoft Word Help 3 May 5th 23 08:50 PM
Copy headers/footers between documents and pages hmm Page Layout 2 April 29th 23 02:52 AM
Copy whole document with Headers/footers DebsPink Page Layout 4 August 15th 09 01:27 PM
Copy everything except headers and footers MarkN Microsoft Word Help 5 August 14th 06 12:36 PM
Copy a Word letter complete with headers and footers to Outlook Art K Microsoft Word Help 6 May 21st 06 04:26 AM


All times are GMT +1. The time now is 05:43 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"