Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TextBox input to Document

Status
Not open for further replies.

bforster1

Programmer
Aug 16, 2006
1
US
I am a newbie but know there must be a simple way to get inputs in a UserForm textbox to a word document.

Thanks in advance.
 
What code have you tried so far?


Andy Baldwin

"Testing is the most overlooked programming language on the books!"

Ask a great question, get a great answer. Ask a vague question, get a vague answer.
Find out how to get great answers FAQ219-2884.
 



Hi,

And where do you want the text inserted in your document?

Skip,

[glasses] [red][/red]
[tongue]
 
There are many ways to put text from a userform into a Word document. Which one you use depends on what your actual requirements are.

To a bookmark in the document:
Code:
ActiveDocument.Bookmarks("A_Bookmark").Range.Text = _
   Userform1.Textbox1.Text

This actually puts the textbox text after the bookmark range. For better code that puts the text INTO the bookmark range see thread707-1266008

To a formfield in the document:
Code:
ActiveDocument.FormFields("Text1").Result = _
    Userform1.Textbox1.Text

To a cell (Row 1, Col 2) in a table (Table 1) in the document:
Code:
ActiveDocument.Tables(1).Cell(1,2).Range.Text = _
    Userform1.Textbox1.Text

Plenty of other examples. Essentially, anything that will TAKE text....will take text.

What exactly do you want to do?


Gerry
My paintings and sculpture
 
I am converting a macro that was created in 1996 to current VBA.

Does any one know the the VBA Syntax for the this wordbasic statement?

WordBasic.NextCell

I have tried using this statement.

Selection.Move Unit:=wdCell, Count:=1

It works if the cell has already been created. When the Nextcell statement is used it performs the same function as the TAB key, which is great. It creates the cell and moves the cursor to that cell.There is a table where each row has 2 columns and the first row is updated numerically. I need the code to create the next cell in the next row and update it then create the 2nd cell in the row where the user will then type in there text.

Here is a copy of the 1996 code.

WordBasic.NextCell
WordBasic.InsertField Field:="SEQ stpxseq \n \* MERGEFORMAT"
WordBasic.NextCell

Here is where I am at now.

WordBasic.NextCell

Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:="SEQ stpxseq \n", _
PreserveFormatting:=True


WordBasic.NextCell

Any suggestions would be greatly appreciated,

Thanks
 
OK first of all, I am slightly confused, which of course is not all that unusual.

You have a table, let's say it has ONE row, TWO columns. If the Selection is in Cell(1,1), then:
Code:
With Selection
[COLOR=red]' move to next cell, SAME row[/color red]
   .MoveRight Unit:=wdCell

[COLOR=red]' CREATE new row with TWO columns[/color red]
   .MoveRight Unit:=wdCell
[COLOR=red]' insert your field - this is in Cell(2,1)[/color red]
   .Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
       Text:="SEQ stpxseq \n", _
       PreserveFormatting:=True
[COLOR=red]' move selection into NEXT cell for 
' user input[/color red]
   .MoveRight Unit:=wdCell
End With
assuming the selection is in the first cell Row1, will move the selection into the next cell(1,2), create the next row - WITH two columns -, insert the field into Cell(2,1), then move the selection into the next cell.
I need the code to create the next cell in the next row and update it then create the 2nd cell in the row where the user will then type in there text.
There is a falsehood here. You seem to think that the second cell in the row is created independently. This is not correct.
Code:
Selection.MoveRight Unit:=wdCell
will either:

A) move the Selection to the next cell in the current row;

OR

B) move the selection to the first cell of the next row;

OR

C) make a new row which will have the SAME number of columns as the row it is exiting.

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top