Cut and Paste via code works differently then Cut and Paste manual

K

Keith Franklin

This is in Word 200

Created a document with header, body and foote

In code select everything and then paste into new documen
Dim word1 As Word.Applicatio
Dim word2 As Word.Applicatio
Set word1 = CreateObject("Word.Application"
word1.Visible = Tru

word1.Documents.Open ("C:\TestPasteSource.doc"

word1.ActiveDocument.Sections(1).Range.Selec
word1.ActiveDocument.Range.Cop
word1.Documents.Ad
word1.ActiveDocument.Selec
word1.Selection.Past

The new document will have everything including Header and Footer..

Create a new instance of Word instead and paste into new document and the Header and Footer wont be paste

Set word2 = CreateObject("Word.Application"
word2.Visible = Tru

word2.Documents.Ad
word2.Selection.Past

If instead of creating the new instance in code you start Word on its own and paste then the header and footer will be pasted

This has got to be some sort of options..

This behavior is different then Office 97 (Helping troubleshoot an application that used Office 97 now going to Office 2003)
 
H

Howard Kaikow

Many things work differently thru the GUI, because Word is doing things for
you that you must explicitly do separately within a macro.

Your macro will have to copy each header and footer separately.

--
http://www.standards.com/; See Howard Kaikow's web site.
Keith Franklin said:
This is in Word 2003

Created a document with header, body and footer

In code select everything and then paste into new document
Dim word1 As Word.Application
Dim word2 As Word.Application
Set word1 = CreateObject("Word.Application")
word1.Visible = True

word1.Documents.Open ("C:\TestPasteSource.doc")

word1.ActiveDocument.Sections(1).Range.Select
word1.ActiveDocument.Range.Copy
word1.Documents.Add
word1.ActiveDocument.Select
word1.Selection.Paste

The new document will have everything including Header and Footer...

Create a new instance of Word instead and paste into new document and the
Header and Footer wont be pasted
Set word2 = CreateObject("Word.Application")
word2.Visible = True

word2.Documents.Add
word2.Selection.Paste


If instead of creating the new instance in code you start Word on its own
and paste then the header and footer will be pasted.
This has got to be some sort of options...

This behavior is different then Office 97 (Helping troubleshoot an
application that used Office 97 now going to Office 2003)
 

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