Hi, I'm using Word 03. I'm missing something here, but I want to insert the
text obtained from the user responding to the InputBox, here's what I have:

Sub newtest()
Dim Message, Title, Default
Dim MyValue As String

Selection.TypeParagraph
Selection.TypeText ("BLACKLINE OF ")
Message = "Blackline of "
Title = "Blackline Footer"
Default = "1"
MyValue = InputBox(Message, Title, Default)
ActiveDocument.Content.InsertAfter ("MyValue") 'does not work

End Sub

Thanks for any advice.

Re: Inserting text gathered from InputBox by Cissy

Cissy
Tue Apr 25 14:22:03 CDT 2006

Thank you for taking the time to explain things. It makes sense and now I
have to go fix my other macros! THANKS

"Jean-Guy Marcil" wrote:

> Cissy was telling us:
> Cissy nous racontait que :
>
> > Hi, I'm using Word 03. I'm missing something here, but I want to
> > insert the text obtained from the user responding to the InputBox,
> > here's what I have:
> >
> > Sub newtest()
> > Dim Message, Title, Default
> > Dim MyValue As String
> >
> > Selection.TypeParagraph
> > Selection.TypeText ("BLACKLINE OF ")
> > Message = "Blackline of "
> > Title = "Blackline Footer"
> > Default = "1"
> > MyValue = InputBox(Message, Title, Default)
> > ActiveDocument.Content.InsertAfter ("MyValue") 'does not work
> >
> > End Sub
> >
> Well, there are many things that are not quite right... let's start with the
> variables:
>
> Dim Message, Title, Default
> Dim MyValue As String
>
> My is defined as a String. Good. But what about Message, Title and Default?
> It is not good practice to let the compiler decide in your place what type
> of variable to use. So, it should be:
>
> Dim Message As String, Title As String, Default As String
> Dim MyValue As String
>
> But this is minor.
> More major is this:
> ActiveDocument.Content.InsertAfter ("MyValue")
>
> Here, you are not telling the compiler to insert the value of the variable
> called "MyValue", but to insert the actual text "MyValue". Quotation marks
> in code identify the enclosed content as pure text to be used as is.
> So, it should have been:
> ActiveDocument.Content.InsertAfter MyValue
>
> Next,
>
> Selection.TypeParagraph
> Selection.TypeText ("BLACKLINE OF ")
>
> These two, lines tell the compiler to insert a paragraph mark and the text
> "BLACKLINE OF " at the cursor position in the document.
> Then
>
> ActiveDocument.Content.InsertAfter MyValue
>
> Inserts the value entered by the user in the InputBox at the End of the
> document. Content returns a Range representing the whole document (Well, not
> quite, the Whole main story).
>
> Is this what you want?
>
> Maybe it should be:
>
> '_______________________________________
> 'Define the variable for the InputBox
> Dim Message As String, Title As String, Default As String
> 'Define the variable for InputBox result
> Dim MyValue As String
> 'Define the variable for the current range
> Dim CurRange As Range
>
>
> Set CurRange = Selection.Range
>
> Message = "Blackline of "
> Title = "Blackline Footer"
> Default = "1"
> 'Get user imput
> MyValue = InputBox(Message, Title, Default)
> 'Use the range from the current selection
> With CurRange
>
> 'Collpase current selection to end of range in case
> 'current selection is not an insertion point
> .Collapse wdCollapseEnd
> 'Insert the ¶
> .InsertParagraphAfter
> 'Insert the text
> .InsertAfter "BLACKLINE OF " & MyValue
> End With
> '_______________________________________
>
> ???
>
> --
> Salut!
> _______________________________________
> Jean-Guy Marcil - Word MVP
> jmarcilREMOVE@CAPSsympatico.caTHISTOO
> Word MVP site: http://www.word.mvps.org
>
>
>

Re: Inserting text gathered from InputBox by Jean-Guy

Jean-Guy
Tue Apr 25 13:54:54 CDT 2006

Cissy was telling us:
Cissy nous racontait que :

> Hi, I'm using Word 03. I'm missing something here, but I want to
> insert the text obtained from the user responding to the InputBox,
> here's what I have:
>
> Sub newtest()
> Dim Message, Title, Default
> Dim MyValue As String
>
> Selection.TypeParagraph
> Selection.TypeText ("BLACKLINE OF ")
> Message = "Blackline of "
> Title = "Blackline Footer"
> Default = "1"
> MyValue = InputBox(Message, Title, Default)
> ActiveDocument.Content.InsertAfter ("MyValue") 'does not work
>
> End Sub
>
Well, there are many things that are not quite right... let's start with the
variables:

Dim Message, Title, Default
Dim MyValue As String

My is defined as a String. Good. But what about Message, Title and Default?
It is not good practice to let the compiler decide in your place what type
of variable to use. So, it should be:

Dim Message As String, Title As String, Default As String
Dim MyValue As String

But this is minor.
More major is this:
ActiveDocument.Content.InsertAfter ("MyValue")

Here, you are not telling the compiler to insert the value of the variable
called "MyValue", but to insert the actual text "MyValue". Quotation marks
in code identify the enclosed content as pure text to be used as is.
So, it should have been:
ActiveDocument.Content.InsertAfter MyValue

Next,

Selection.TypeParagraph
Selection.TypeText ("BLACKLINE OF ")

These two, lines tell the compiler to insert a paragraph mark and the text
"BLACKLINE OF " at the cursor position in the document.
Then

ActiveDocument.Content.InsertAfter MyValue

Inserts the value entered by the user in the InputBox at the End of the
document. Content returns a Range representing the whole document (Well, not
quite, the Whole main story).

Is this what you want?

Maybe it should be:

'_______________________________________
'Define the variable for the InputBox
Dim Message As String, Title As String, Default As String
'Define the variable for InputBox result
Dim MyValue As String
'Define the variable for the current range
Dim CurRange As Range


Set CurRange = Selection.Range

Message = "Blackline of "
Title = "Blackline Footer"
Default = "1"
'Get user imput
MyValue = InputBox(Message, Title, Default)
'Use the range from the current selection
With CurRange

'Collpase current selection to end of range in case
'current selection is not an insertion point
.Collapse wdCollapseEnd
'Insert the ¶
.InsertParagraphAfter
'Insert the text
.InsertAfter "BLACKLINE OF " & MyValue
End With
'_______________________________________

???

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org