formatting issue

A

Associates

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
 
G

Gordon Bentley-Mix

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.
 
A

Associates

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

Gordon Bentley-Mix said:
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.


Associates said:
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
 
G

Graham Mayor

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

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

Gordon Bentley-Mix said:
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.


Associates said:
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
 
A

Associates

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


Graham Mayor said:
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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

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

Gordon Bentley-Mix said:
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
 
G

Graham Mayor

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

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


Graham Mayor said:
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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

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
 
A

Associates

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


Graham Mayor said:
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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

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


Graham Mayor said:
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
 
G

Graham Mayor

The purpose of the exercise was to insert a title. I seem to recall that you
were using Macrobutton as a text marker but wanted to run some code on that
text.

The macro run from the macrobutton gives you the opportunity to do that,
however once the title has been inserted, the macrobutton field is replaced
with the title, just as if you had typed in a macrobuttom marker field.

You can do what you want with the string in your myTestMacro before
inserting it, including offering the opportunity to confirm then format the
resulting text as true title case which is entered in place of the field -
as in the following example in which I have included code from my web page
http://www.gmayor.com/word_vba_examples.htm

If the user cannot get it right after all that then he/she will have to
delete the text and type over it!

Sub myTestMacro()
Dim myText As String
Dim sText As Range
Dim sQuery As String
Dim vFindText As Variant
Dim vReplText As Variant
Dim i As Long
Dim k As Long
Dim m As Long
Start:
myText = InputBox("Enter a title here")
sQuery = MsgBox("The title you have inserted contains the text" & vbCr &
vbCr & _
UCase(myText) & vbCr & vbCr & "Is this the correct title?", vbYesNo,
"Title")
If sQuery <> vbYes Then GoTo Start
Set sText = Selection.Range
sText.Text = myText
k = Len(sText)
If k < 1 Then
MsgBox "Select the text first!", vbOKOnly, "No text selected"
Exit Sub
End If
sText.Case = wdTitleWord
vFindText = Array("A", "An", "And", "As", "At", "But", "By", "For", _
"If", "In", "Of", "On", "Or", "The", "To", "With")
vReplText = Array("a", "an", "and", "as", "at", "but", "by", "for", _
"if", "in", "of", "on", "or", "the", "to", "with")
With sText
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.Wrap = wdFindStop
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.format = True
.MatchCase = True
For i = LBound(vFindText) To UBound(vFindText)
.Text = vFindText(i)
.Replacement.Text = vReplText(i)
.Execute Replace:=wdReplaceAll
Next i
End With
.MoveEnd Unit:=wdCharacter, Count:=-Len(sText) + 1
.Case = wdUpperCase
.MoveEnd Unit:=wdCharacter, Count:=k
If InStr(1, sText, ":") > 0 Then
m = InStr(1, sText, ":") + 1
.MoveStart wdCharacter, m
.MoveEnd Unit:=wdCharacter, Count:=-Len(sText) + 1
.Case = wdUpperCase
End If
End With
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

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


Graham Mayor said:
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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

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
 
G

Graham Mayor

Just a thought, you could insert the entered title as a macrobutton field
that would be clickable to repeat the entry eg

Sub myTestMacro()
Dim myText As String
Start:
myText = InputBox("Enter a title here")
If myText = "" Then
MsgBox "You cannot leave this field blank", vbCritical, "Error"
GoTo Start
End If
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldMacroButton, _
Text:="myTestMacro " & myText, _
PreserveFormatting:=False
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Graham said:
The purpose of the exercise was to insert a title. I seem to recall
that you were using Macrobutton as a text marker but wanted to run
some code on that text.

The macro run from the macrobutton gives you the opportunity to do
that, however once the title has been inserted, the macrobutton field
is replaced with the title, just as if you had typed in a macrobuttom
marker field.
You can do what you want with the string in your myTestMacro before
inserting it, including offering the opportunity to confirm then
format the resulting text as true title case which is entered in
place of the field - as in the following example in which I have
included code from my web page
http://www.gmayor.com/word_vba_examples.htm
If the user cannot get it right after all that then he/she will have
to delete the text and type over it!

Sub myTestMacro()
Dim myText As String
Dim sText As Range
Dim sQuery As String
Dim vFindText As Variant
Dim vReplText As Variant
Dim i As Long
Dim k As Long
Dim m As Long
Start:
myText = InputBox("Enter a title here")
sQuery = MsgBox("The title you have inserted contains the text" &
vbCr & vbCr & _
UCase(myText) & vbCr & vbCr & "Is this the correct title?",
vbYesNo, "Title")
If sQuery <> vbYes Then GoTo Start
Set sText = Selection.Range
sText.Text = myText
k = Len(sText)
If k < 1 Then
MsgBox "Select the text first!", vbOKOnly, "No text selected"
Exit Sub
End If
sText.Case = wdTitleWord
vFindText = Array("A", "An", "And", "As", "At", "But", "By", "For", _
"If", "In", "Of", "On", "Or", "The", "To", "With")
vReplText = Array("a", "an", "and", "as", "at", "but", "by", "for", _
"if", "in", "of", "on", "or", "the", "to", "with")
With sText
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.Wrap = wdFindStop
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.format = True
.MatchCase = True
For i = LBound(vFindText) To UBound(vFindText)
.Text = vFindText(i)
.Replacement.Text = vReplText(i)
.Execute Replace:=wdReplaceAll
Next i
End With
.MoveEnd Unit:=wdCharacter, Count:=-Len(sText) + 1
.Case = wdUpperCase
.MoveEnd Unit:=wdCharacter, Count:=k
If InStr(1, sText, ":") > 0 Then
m = InStr(1, sText, ":") + 1
.MoveStart wdCharacter, m
.MoveEnd Unit:=wdCharacter, Count:=-Len(sText) + 1
.Case = wdUpperCase
End If
End With
End Sub


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


Graham Mayor said:
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
 
A

Associates

Thank you Graham,

I'll try that out.

Graham Mayor said:
Just a thought, you could insert the entered title as a macrobutton field
that would be clickable to repeat the entry eg

Sub myTestMacro()
Dim myText As String
Start:
myText = InputBox("Enter a title here")
If myText = "" Then
MsgBox "You cannot leave this field blank", vbCritical, "Error"
GoTo Start
End If
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldMacroButton, _
Text:="myTestMacro " & myText, _
PreserveFormatting:=False
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


Graham said:
The purpose of the exercise was to insert a title. I seem to recall
that you were using Macrobutton as a text marker but wanted to run
some code on that text.

The macro run from the macrobutton gives you the opportunity to do
that, however once the title has been inserted, the macrobutton field
is replaced with the title, just as if you had typed in a macrobuttom
marker field.
You can do what you want with the string in your myTestMacro before
inserting it, including offering the opportunity to confirm then
format the resulting text as true title case which is entered in
place of the field - as in the following example in which I have
included code from my web page
http://www.gmayor.com/word_vba_examples.htm
If the user cannot get it right after all that then he/she will have
to delete the text and type over it!

Sub myTestMacro()
Dim myText As String
Dim sText As Range
Dim sQuery As String
Dim vFindText As Variant
Dim vReplText As Variant
Dim i As Long
Dim k As Long
Dim m As Long
Start:
myText = InputBox("Enter a title here")
sQuery = MsgBox("The title you have inserted contains the text" &
vbCr & vbCr & _
UCase(myText) & vbCr & vbCr & "Is this the correct title?",
vbYesNo, "Title")
If sQuery <> vbYes Then GoTo Start
Set sText = Selection.Range
sText.Text = myText
k = Len(sText)
If k < 1 Then
MsgBox "Select the text first!", vbOKOnly, "No text selected"
Exit Sub
End If
sText.Case = wdTitleWord
vFindText = Array("A", "An", "And", "As", "At", "But", "By", "For", _
"If", "In", "Of", "On", "Or", "The", "To", "With")
vReplText = Array("a", "an", "and", "as", "at", "but", "by", "for", _
"if", "in", "of", "on", "or", "the", "to", "with")
With sText
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Forward = True
.Wrap = wdFindStop
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.format = True
.MatchCase = True
For i = LBound(vFindText) To UBound(vFindText)
.Text = vFindText(i)
.Replacement.Text = vReplText(i)
.Execute Replace:=wdReplaceAll
Next i
End With
.MoveEnd Unit:=wdCharacter, Count:=-Len(sText) + 1
.Case = wdUpperCase
.MoveEnd Unit:=wdCharacter, Count:=k
If InStr(1, sText, ":") > 0 Then
m = InStr(1, sText, ":") + 1
.MoveStart wdCharacter, m
.MoveEnd Unit:=wdCharacter, Count:=-Len(sText) + 1
.Case = wdUpperCase
End If
End With
End Sub


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
 

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