Inserting AutoText in Header and retaining formatting 
Author Message
 Inserting AutoText in Header and retaining formatting

I printed an article from 11-4-02 posted in the
vba.Beginners newsgroup and can not locate it to add an
additional question.  The topic was similar-- "Inserting
AutoText from a Global Template".

I had the same situation as the posted message.
How to insert AutoText stored in a Global template in to a
document.  Except mine needs to go in the Header then add
Diff first page and add the AutoText in there as well.

Problems I am running into:
1. It won't put the AutoText in the Header or dif first
page.
2. Removes formatting of AutoText (Which I need)

Here is my code.

'ViewHeaderFooter()
    With ActiveDocument.Sections(1).Headers_
(wdHeaderFooterPrimary)
'InsertMCSOLines()
    Dim oTemp As Template
    Set oTemp = Word.Templates(Options.DefaultFilePath_
wdStartupPath) & "\Firm.dot")
        oTemp.AutoTextEntries("Pld21lines").Insert _
        Where:=Selection.Range
    End With
'Add MCSOLines to DIfferent First Page
  ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter _
= True
    With ActiveDocument.Sections(1).Headers_
(wdHeaderFooterFirstPage)
        oTemp.AutoTextEntries("Pld21lines").Insert _
        Where:=Selection.Range
    End With

I have been trying to figure this out for way to
long...I'd really appreciate any help you can provide.  I
only have "Basic VBA" knowledge.

Thank you!!
Kerri



Sat, 07 May 2005 02:21:56 GMT  
 Inserting AutoText in Header and retaining formatting
Hi Kerri,

To get the formatted text of an AutoText, set its RichText property to true,
as in the following example:


Quote:
> I printed an article from 11-4-02 posted in the
> vba.Beginners newsgroup and can not locate it to add an
> additional question.  The topic was similar-- "Inserting
> AutoText from a Global Template".

> I had the same situation as the posted message.
> How to insert AutoText stored in a Global template in to a
> document.  Except mine needs to go in the Header then add
> Diff first page and add the AutoText in there as well.

> Problems I am running into:
> 1. It won't put the AutoText in the Header or dif first
> page.
> 2. Removes formatting of AutoText (Which I need)

> Here is my code.

> 'ViewHeaderFooter()
>     With ActiveDocument.Sections(1).Headers_
> (wdHeaderFooterPrimary)
> 'InsertMCSOLines()
>     Dim oTemp As Template
>     Set oTemp = Word.Templates(Options.DefaultFilePath_
> wdStartupPath) & "\Firm.dot")
>         oTemp.AutoTextEntries("Pld21lines").Insert _
>         Where:=Selection.Range
>     End With
> 'Add MCSOLines to DIfferent First Page
>   ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter _
> = True
>     With ActiveDocument.Sections(1).Headers_
> (wdHeaderFooterFirstPage)
>         oTemp.AutoTextEntries("Pld21lines").Insert _
>         Where:=Selection.Range
>     End With

> I have been trying to figure this out for way to
> long...I'd really appreciate any help you can provide.  I
> only have "Basic VBA" knowledge.

> Thank you!!
> Kerri



Sat, 07 May 2005 02:45:48 GMT  
 Inserting AutoText in Header and retaining formatting
Hi Kerri,

To get the formatted text of an AutoText, set its RichText property to true,
as in the following example:

ActiveDocument.AttachedTemplate.AutoTextEntries("one").Insert _
    Where:=Selection.Range, RichText:=True

As for the location, I think you should set the pagesetup properties first,
create a range object for the different first page header, and then set the
Where parameter to equal that range, as in the following:

Dim oRng As Range
With ActiveDocument.PageSetup
    .DifferentFirstPageHeaderFooter = True
    .OddAndEvenPagesHeaderFooter = True
End With
Set oRng = ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range
' insert an AutoText from a global template example:
Templates(Options.DefaultFilePath(wdStartupPath) &
"\Globals.dot").AutoTextEntries("BMC").insert Where:=oRng, RichText:=True

HTH

Quote:

> Hi Kerri,

> To get the formatted text of an AutoText, set its RichText property to
true,
> as in the following example:



> > I printed an article from 11-4-02 posted in the
> > vba.Beginners newsgroup and can not locate it to add an
> > additional question.  The topic was similar-- "Inserting
> > AutoText from a Global Template".

> > I had the same situation as the posted message.
> > How to insert AutoText stored in a Global template in to a
> > document.  Except mine needs to go in the Header then add
> > Diff first page and add the AutoText in there as well.

> > Problems I am running into:
> > 1. It won't put the AutoText in the Header or dif first
> > page.
> > 2. Removes formatting of AutoText (Which I need)

> > Here is my code.

> > 'ViewHeaderFooter()
> >     With ActiveDocument.Sections(1).Headers_
> > (wdHeaderFooterPrimary)
> > 'InsertMCSOLines()
> >     Dim oTemp As Template
> >     Set oTemp = Word.Templates(Options.DefaultFilePath_
> > wdStartupPath) & "\Firm.dot")
> >         oTemp.AutoTextEntries("Pld21lines").Insert _
> >         Where:=Selection.Range
> >     End With
> > 'Add MCSOLines to DIfferent First Page
> >   ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter _
> > = True
> >     With ActiveDocument.Sections(1).Headers_
> > (wdHeaderFooterFirstPage)
> >         oTemp.AutoTextEntries("Pld21lines").Insert _
> >         Where:=Selection.Range
> >     End With

> > I have been trying to figure this out for way to
> > long...I'd really appreciate any help you can provide.  I
> > only have "Basic VBA" knowledge.

> > Thank you!!
> > Kerri



Sat, 07 May 2005 02:52:47 GMT  
 Inserting AutoText in Header and retaining formatting
Thank you Dave for your help!  That's what I needed to get
going.  Here is my final code for anyone else having the
same issues....I wanted it to insert the AutoText in to
both the first page header and Primary header and have it
formatted.  It is probably a little sloppy...but it
worked.  THANK YOU!!!!!!

Sub Insertlines()
'Insert Autotext into Header
Dim oRng2 As Range
Set oRng2 = ActiveDocument.Sections(1).Headers_
(wdHeaderFooterPrimary).Range
With oRng2
'InsertMCSOLines()
    Dim oTemp As Template
    Set oTemp = Word.Templates(Options.DefaultFilePath_
(wdStartupPath) & "\Firm.dot")
        oTemp.AutoTextEntries("Pld21lines").Insert_
Where:=oRng2, RichText:=True
    End With

Dim oRng As Range
With ActiveDocument.PageSetup
    .DifferentFirstPageHeaderFooter = True
End With
    Set oRng = ActiveDocument.Sections(1).Headers_
(wdHeaderFooterFirstPage).Range

' insert an AutoText from a global template example:

With oRng
'    Set oTemp = Templates(Options.DefaultFilePath
(wdStartupPath) & "\Firm.dot")_
    oTemp.AutoTextEntries("Pld21lines").Insert_
Where:=oRng, RichText:=True
End With
End Sub

Quote:
>-----Original Message-----
>Hi Kerri,

>To get the formatted text of an AutoText, set its

RichText property to true,
Quote:
>as in the following example:

>ActiveDocument.AttachedTemplate.AutoTextEntries
("one").Insert _
>    Where:=Selection.Range, RichText:=True

>As for the location, I think you should set the pagesetup
properties first,
>create a range object for the different first page

header, and then set the
Quote:
>Where parameter to equal that range, as in the following:

>Dim oRng As Range
>With ActiveDocument.PageSetup
>    .DifferentFirstPageHeaderFooter = True
>    .OddAndEvenPagesHeaderFooter = True
>End With
>Set oRng = ActiveDocument.Sections(1).Headers

(wdHeaderFooterFirstPage).Range
Quote:
>' insert an AutoText from a global template example:
>Templates(Options.DefaultFilePath(wdStartupPath) &
>"\Globals.dot").AutoTextEntries("BMC").insert

Where:=oRng, RichText:=True
Quote:

>HTH



>> Hi Kerri,

>> To get the formatted text of an AutoText, set its

RichText property to
Quote:
>true,
>> as in the following example:



>> > I printed an article from 11-4-02 posted in the
>> > vba.Beginners newsgroup and can not locate it to add
an
>> > additional question.  The topic was similar--
 "Inserting
>> > AutoText from a Global Template".

>> > I had the same situation as the posted message.
>> > How to insert AutoText stored in a Global template in
to a
>> > document.  Except mine needs to go in the Header then
add
>> > Diff first page and add the AutoText in there as well.

>> > Problems I am running into:
>> > 1. It won't put the AutoText in the Header or dif
first
>> > page.
>> > 2. Removes formatting of AutoText (Which I need)

>> > Here is my code.

>> > 'ViewHeaderFooter()
>> >     With ActiveDocument.Sections(1).Headers_
>> > (wdHeaderFooterPrimary)
>> > 'InsertMCSOLines()
>> >     Dim oTemp As Template
>> >     Set oTemp = Word.Templates

(Options.DefaultFilePath_
Quote:
>> > wdStartupPath) & "\Firm.dot")
>> >         oTemp.AutoTextEntries("Pld21lines").Insert _
>> >         Where:=Selection.Range
>> >     End With
>> > 'Add MCSOLines to DIfferent First Page

ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter _

- Show quoted text -

Quote:
>> > = True
>> >     With ActiveDocument.Sections(1).Headers_
>> > (wdHeaderFooterFirstPage)
>> >         oTemp.AutoTextEntries("Pld21lines").Insert _
>> >         Where:=Selection.Range
>> >     End With

>> > I have been trying to figure this out for way to
>> > long...I'd really appreciate any help you can
provide.  I
>> > only have "Basic VBA" knowledge.

>> > Thank you!!
>> > Kerri

>.



Mon, 09 May 2005 01:45:26 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Problem with format on insert autotext, and in inserting elements with form fields

2. Retaining original formatting on inserted docs

3. Retaining HTML formatting when inserting into a word document

4. Inserting Autotext using VBA - loses formatting and styles

5. Insert Autotext - returned range depends on formatting?

6. Macro that inserts Autotext loses styles of Autotext entry

7. Help Replace Headers Footers w/ Autotext?

8. Deleting "Draft" Autotext in Header

9. Deleting "Draft" WordArt AutoText in Header

10. Using Autotext in Headers in Templates: Doesn't update

11. Inserting AutoText from a Global Template

12. Insert autotext with VBa

 

 
Powered by phpBB® Forum Software