Inserting AutoText in Header adds extra paragraph marks

V

voip1234

I am trying to insert AutoText into Headers in my document.
I carefully selected just what is needed to create the
autotext, but when I insert the autotext into the header
it adds an extra paragraph mark (the mirrored 'P').
This cause problems because all my document gets reflowed.
Can somebody please help me figure out how I can either
delete the paragraph marks or have them not be inserted
in there in the first place please?
My current code to insert the autotext is the following

ActiveDocument.AttachedTemplate.AutoTextEntries _ ("myAutoText").Insert
_
Where:=ActiveDocument.Sections(i).Headers _
wdHeaderFooterPrimary).Range, _
RichText:=True

the 'i' is the index for the loop that goes through all
my sections.

I have also tried to add a delete line before that command
but that didnt help either. I used

ActiveDocument.Sections(i).Header _
(wdHeaderFooterPrimary).Range.Delete

I have checked and rechecked and as far as I can see
my autotext (which includes its style) does not have
the extra paragraph marks.

How can I avoid these marks in the first place or
how can I convert the following code to work inside
the ranges?

Selection.EndKey Unit:=wdLine
Selection.Delete Unit:=wdCharacter, Count:=1
This would do what I need.

thanks for the help.
 
C

Charles Kenyon

The only way I know to make this happen is to include the paragraph mark in
the AutoText entry when it is created.
 
V

voip1234

I dont understand what you mean, I want to remove the
additional one that is inserted, not add another one.
My autotext entry is the complete selection of a manually
made header, so it does include ONE paragraph mark.
After I programatically insert the autotext entries,
now my headers have two paragraph marks. I only want
one cause the second one cause text reflow.
Anythin I should try? Even a routine that goes in, finds
paragraph marks and removes them would work.
thanks.
 
H

Howard Kaikow

Try the following, I used a built-in autotext.

Private Sub InsertAutoTextInHeader()
Dim sec As Word.Section

For Each sec In ActiveDocument.Sections
NormalTemplate.AutoTextEntries("Confidential, Page #, Date").Insert
_
Where:=sec.Headers(wdHeaderFooterPrimary).Range, RichText:=True
Next sec
End Sub

Should not insert any extra pilcrow character mark.

If it does insert the extra critter, then I expect that your styles are
causing extra paragraph to be inserted.
 
V

voip1234

I will try it, but I dont see how this will remove the extra paragraph
marks....i'm a little confused.
 
H

Howard Kaikow

It won't.

It is intended to demonstrate with the insertion works correctly.

If it does, then you need to correct the AutoText entry itself.
 
V

voip1234

Ok, got it....you are right. If i use that line which is the exact one
I use for my autotext it works correctly. Bu the thing is I need to
select the paragraph mark in my autotext cause that is where the style
information is located in. Or at least thats what I think. If I create
the autotext selecting only the text and not include the paragraph
mark, then only the plain text is inserted. If I select the paragraph
mark along with the rest of the text, then when I insert the autotext,
it does come in with the right style.... but with an extra paragraph
mark.
Any idea how I can delete the extra paragraph marks in the headers once
the autotexts have been inserted?
thanks for your help, it is very much appreciated
 
H

Howard Kaikow

Create the AutoText entry without selecting the paragraph mark and make sure
the right formatting is applied directly to the text.
 
V

voip1234

how would I be able to do that if my formatting includes a specific tab
sequence and a double line under the text? Isnt one supposed to use
styles for that?
Is there a way to simply go in and remove the extra paragraph marks? If
I go in manually and press the END key followed by the DELETE key, I
get exactly what I want....how could I automated that so that it gets
done in all of my headers?
 
V

voip1234

I finally solved it...dont know if this was the right way, but it
works...this is what I did

My AutoText entry is a fill line of text with 2 docvaribles and a
paragraph style applied to it. Because of this, I found no way to
insert the autotext without the end paragraph mark. It was this mark
that was causing me problems. Since I ended up with 2 paragraph marks.
on each header and that cause text reflow further down the document.
My solution was to simply delete a character at the text once it was
placed in the header. I dont know if this is the most efficient way,
but this was the end product.

ActiveDocument.AttachedTemplate.AutoTextEntries("atUniFolVerNon").Insert
_
Where:=ActiveDocument.Sections(i).Headers(wdHeaderFooterPrimary).Range,
_
RichText:=True

Dim rMyRng As Range
Set rMyRng = .Headers(wdHeaderFooterPrimary).Range
With rMyRng
..Collapse Direction:=wdCollapseEnd
..Delete Unit:=wdCharacter, Count:=1
End With

if anybody has a better idea, please post it so I can compare and
learn.
thanks for all the input and help!!!!
 
C

Charles Kenyon

Change the style of the paragraph in which you are inserting the AutoText to
be the style you want when you finish. Since you are programming this in
vba, it shouldn't be a big extra step. That way you don't need the paragraph
mark in the AutoText entry itself.
 
V

voip1234

I tried that once, but I am VERY new to vba and programming, so I found
the commands to type he text into the header, and was only able to find
a command to add the DocVariables at the end or at the beginning of the
text, not in the middle...I wasnt able to figure out what command to
use to insert the style in either. I tried to insert the style while
macro recorder was on to see what command it used, but I wasnt able to
translate the
selection commands to range commands....i guess I will keep trying to
improve on the code. The good thing is that right now, he paragraph
marks are being removed and the program works. Now I will figure out
how to optimize it.
thanks for all your help.
 

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