Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2006

Tip: Looking for answers? Try searching our database.

Inserting text gathered from InputBox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Cissy - 25 Apr 2006 19:11 GMT
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.
Jean-Guy Marcil - 25 Apr 2006 19:54 GMT
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,
[quoted text clipped - 13 lines]
>
> 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
'_______________________________________

???

Signature

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

Cissy - 25 Apr 2006 20:22 GMT
Thank you for taking the time to explain things.  It makes sense and now I
have to go fix my other macros!  THANKS

> Cissy was telling us:
> Cissy nous racontait que :
[quoted text clipped - 88 lines]
>
> ???
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.