Paragraph style before and after an input box

D

Dan

Hi,

I have a macro set up to insert text using an input box in a particular style but the style is applied to the text before and after the inputted text, how can i Stop this?

Here is my code


Dim myKeyword As String

myKeyword = InputBox("Enter your keyword.", " Insert Keyword", "Insert your key word here")

Selection.TypeText (myKeyword)
Selection.Style = "Key Words"

ActiveDocument.Indexes.MarkEntry Range:=Selection.Range, Entry:=myKeyword, EntryAutoText:=myKeyword

End Sub

Thanks

Dan
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Dan > écrivait :
In this message, < Dan > wrote:

|| Hi,
||
|| I have a macro set up to insert text using an input box in a particular
style but the style is
|| applied to the text before and after the inputted text, how can i Stop
this?
||
|| Here is my code
||
||
|| Dim myKeyword As String
||
|| myKeyword = InputBox("Enter your keyword.", " Insert Keyword", "Insert
your key word here")
||
|| Selection.TypeText (myKeyword)
|| Selection.Style = "Key Words"
||
|| ActiveDocument.Indexes.MarkEntry Range:=Selection.Range,
Entry:=myKeyword,
|| EntryAutoText:=myKeyword
||
|| End Sub

What kind of style is "Key Words"?
If it is a paragraph style, then the result is totally predictable. A
paragraph style applies to a... paragraph! Since you insert text without
making sure it is a paragraph of its own, the style modifies the whole
paragraph (Presumable the text before and after you refer to).

Either you make sure the inserted text sits on a single paragraph, or if
that is not what you want, change "Key Words" to a Character style.
Alternatively, select the inserted text and change its formatting through
the macro, but that can be messy.

I would say the Character style is the easiest, but some users are not
comfortable with them.
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
D

Dan

Hi,

I have chaged the style to a character and it now inserts the text in the correct style before the insertion but I cant work out how to program the macro to chnage the style back to normal after the text has been put in. If you continue typing after the insertion it is in the "Key Words" style. Is it possible to add this to the macro to change the style back automatically so you dont have to do it manually each time?

Thanks

Dan
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Dan > écrivait :
In this message, < Dan > wrote:

|| Hi,
||
|| I have chaged the style to a character and it now inserts the text in the
correct style before
|| the insertion but I cant work out how to program the macro to chnage the
style back to normal
|| after the text has been put in. If you continue typing after the
insertion it is in the "Key
|| Words" style. Is it possible to add this to the macro to change the style
back automatically so
|| you dont have to do it manually each time?
||

Try adding this line once the cursor is positioned where you want the user
to work from:

Selection.Font.Reset

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.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