Thanks Graham,
It works now.
The other thing i have noticed is that it only works once. By that i
mean, you can not double click it anymore as the MACROBUTTON has been
replaced by myText already.Is there any way of getting the inputbox
to show up if that field is double-clicked again? just in case if the
user makes a mistake in the title and wants to correct it.
Thank you in advance
:
How about:
Sub InsertNewSection()
With Selection
.Fields.Add Range:=Selection.Range,
Type:=wdFieldMacroButton, _ Text:="myTestMacro [double click
to insert title]", _ PreserveFormatting:=False
.Delete Unit:=wdCharacter, Count:=1
.MoveRight Unit:=wdCharacter, Count:=1
.Style = ActiveDocument.Styles("Document Heading 2")
End With
End Sub
Sub myTestMacro()
Dim sText As Range
Dim myText As String
myText = InputBox("Enter a title here")
Set sText = Selection.Range
sText.Text = myText
End Sub
You need to watch your use of the style and where your cursor is
when you insert the field with the macro of you may lose the
following character and format the whole paragraph.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site
www.gmayor.com
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Associates wrote:
Thank you Graham for your reply.
I think that is exactly what i needed.
However, i need further help with this.
This is what i have done
Sub InsertNewSection()
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
_ PreserveFormatting:=False
Selection.TypeText Text:="MACROBUTTON myTestMacro [double click
to insert title]"
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.Style = ActiveDocument.Styles("Document Heading 2")
...
End Sub
Sub myTestMacro()
myText = InputBox("Enter a title here")
' But do not know how to put the text into the document
Selection.Fields(2) = myText
End Sub
My issue here is that i donot know how to put myText back to the
document.
Thanks for your help in advance
:
Why not use the macrobutton field in conjunction with a macro to
call an input box to collect and format the data for this field?
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site
www.gmayor.com
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Associates wrote:
Thanks for your reply.
I guess there is no particular reason for using that. It's just
that it's
the only one that i can think of that allows more flexibility to
the users than form field.
What i mean by that is with the formfield, you need to determine
the width
of the box beforehand in order to accomodate the full texts.
for an extreme example, say we have a long title for Chapter 1
that might takes more than one line.
Chapter 1 blahblah balhblah blahblahblahblahblahblah
blahblahblahblah blahblah
and if i set the width shorter than the texts entered by user,
there will be a problem (some will get chopped off)
Hope i explained it well.
Thank you in advance
:
Is there a particular reason that you're using a macrobutton?
Because doing so definitely restricts what you can do.
Macrobuttons are really intended to execute a macro when
double-clicked, and unfortunately there is no Exit event for
macrobuttons that you could write code against.
If you used a regular formfield then this would be easy - just
call your "capitalisation" macro when you exit the field. You
can even make it so the instructional text is displayed and
removed automatically, as I described in the post "Help with
text form fields and instructional text" on 8 Sept. Otherwise, I
can't see any easy way of making this work. --
Cheers!
Gordon
Uninvited email contact will be marked as SPAM and ignored.
Please post all follow-ups to the newsgroup.
:
Hi,
In the word document, i have the following line of text
Chapter 1 {MACROBUTTON NOMACRO [Please enter the title here]}
eg. Chapter 1 International monetary fund
My issue here is that people might be entering the title as
shown in the above example when our company policy says it
should be "International Monetary Fund". You may notice that we
require people to put an upper case to the first letter of
every words that may exist there. I have a function in VBA code
that enforce that policy. However, i just don't know how or
when to trigger that function.
appreciate your help.
Thank you in advance