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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word combobox question

Status
Not open for further replies.

Shaunfish

Technical User
Mar 3, 2023
2
0
0
ZA
I have two word documents, one is a list of item definitions and the other is a form. I need to create a combo box on the form with a list of items, when an item is selected, I need for the definition to be displayed on the form. How do I link the two documents? Is it even possible?

Regards

Shaun
 
Hi Shaun,

It is possible to do what you are asking for. Do the two documents need to be Word? Can you use Excel instead?

The reason that I am asking is that performing the task in Word is 10x harder.

One thing to keep in mind is that Word VBA and Excel VBA are different in a lot of ways. Word VBA is a major pain compared to Excel VBA sit it is very rarely used.

The amount of time researching the Word equivalent of Excel VBA will be significant. Also, I've never met another person that can program Word VBA. This means that if you win the lottery, who can maintain and update the files?
 
This is just a guess, but this is what I imagine in your document one:

[pre]
Item Definition
Item A This is Item A's definition
Item B Some description on this Item
goes here
Item X Another definition that applies
to Item X that needs to be displayed
in another document
[/pre]
I am with remeng, Word is a bad choice, but even Excel has its limits of how much text you can fit into one cell. If your Definitions are long, Excel may not be a good choice, either.

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Hi all
Unfortunately is does have to be in word. The definitions are quite long, as in a paragraph of text. I suppose I could hard code the paragraphs but really don't want to do this. One think with with vba it would be a relative simple task.

I have managed to get vba to read in the definitions but now the trick is to paste it to the correct place in the report doc. I tried using text field but for some reason only a few words are displayed even after telling word that there is now word limit to the text field.

Regards
Shaun
 
>I tried using text field

Why not try using a bookmark? And then something like the following:

Code:
[COLOR=blue]Public Sub example()
    InsertTextInBookmark "Insertionpoint", "Just some simple text"
End Sub

Sub InsertTextInBookmark(strBookmark As String, strText As String)
  Dim oRng As Word.Range
  Set oRng = ActiveDocument.Bookmarks(strBookmark).Range
  oRng.Text = strText [COLOR=green]' overwrites  bookmark[/color]
  [COLOR=green]' reset bookmark[/color]
  ActiveDocument.Bookmarks.Add strBookmark, oRng
End Sub[/color]
 
Strongm has the correct approach.

You'll need bookmarks, custom style, and tables to get the result that you are looking for.

The bookmark will allow you to define the location in the word document, the Style will allow you to correctly format the information from one word doc to another, and the table will create a default location for the text / paragraph to go.

With the table, you can assign it a name and use the index to define the cell location to paste to. After you test the macros and are happy with it, you can either leave the border showing or set it to white to hide it. NOTE: tables in Word do not have the same VBA code or formatting as Excel.

here is a thread I created about showing and hiding bookmarks. It might give you a little insight into how they can work Link

here is a link to vba with word tables: Link

Another good resource: Link

Coding tables: Link

Give those a quick look. I think those are good research starting points.
 
>Word VBA and Excel VBA are different in a lot of ways

Point of prder: Excel VBA and Word VBA are the same. It is the host applications' object models that differ.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top