Solved

Microsoft Word Pop Up Form

Posted on 2016-10-25
7
40 Views
Last Modified: 2016-10-25
I have several tables in a Word document.  Within each table, I have a designated cell for configuring a reporting function.
The contents of the cell is a delimited string full of configuration information.

Example:     name1=value1~name2=value2~name3=value3, etc

I would like the user to be able to double click or some other action to yield a pop up form that would present an input box for each name value pair allowing them to edit the cell through the pop up.

Any suggestions on approach to do this appreciated.
0
Comment
Question by:maxdbase
  • 3
  • 3
7 Comments
 
LVL 18

Expert Comment

by:xtermie
ID: 41858470
You can add a Fill-in field in the cell you want, and even have a field prompt
You would have to give an initial value and then the field would popup once you either
a) right click and select update
or
b) press F9

In Quick Parts (Insert ribbon) select Field and you will find the fill-in
You can check more fields, as you may find something more appropriate
0
 

Author Comment

by:maxdbase
ID: 41858487
Screenshot:  
http://www.screencast.com/t/5ahbpAzrHgzV

Yes, if I could have the prompt be multiple fields and then map back to the cell that would do it.
0
 

Author Comment

by:maxdbase
ID: 41858499
The Macro seems to be able to allow for a pop up like this:

http://www.screencast.com/t/FdJ5KjO3Z9w8

I would need to open the pop up from the cell.  How do that?

Then map the fields back to the cell.  Assume that would be a vba thing linked to a button
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:maxdbase
ID: 41858521
http://www.screencast.com/t/0u2coPfzCqRY

The above is pretty close, I just need to be able to identify the selected cell in the vba then map the contents
of the form fields back to that cell.  Any sample code to do this will answer the question.
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 41858548
In VBA it isn't possible to hook mouse actions over the document, so It would be better to run a macro from a QAT button and/or a shortcut keystroke. The macro would show the Userform.

Code in the userform's Initialize event could capture the text and display it in text boxes. If there are likely to be quite a few items, you could use a listbox and have some code to copy the seleted line into two text boxes for editing.

Let us know if you need any further advice on the code.
0
 
LVL 18

Expert Comment

by:xtermie
ID: 41858617
To create a table from an Excel file, you must either create an Excel file or use one you already have and change the path in the code to point to it.
To insert this field using the Word object model, use the Fields.Add method:

Sub Test
    Dim rng as Word.Range
    Dim xlRange as String
    xlRange = "Sheet1!R12C1:R18C3"
    Set rng = Selection.Range
    ' Note that backslashes in field paths must be doubled.
    LinkTable rng, "C:\\test\\yourExcelFile.xls", xlRange, "\h"
End Sub
Sub LinkTable(rng As Word.Range, path As String, _
    xlRange As String, linkFormat As String)
  
    Dim fieldText As String
    Dim fld As Word.Field
    
    fieldText = "Excel.Sheet.8 " & Chr$(34) & path _
        & Chr$(34) & " " & Chr$(34) & xlRange & Chr$(34) _
            & linkFormat
    ' Insert the field code as text.
    rng.Text = fieldText & vbCr
    rng.Collapse Direction:=wdCollapseEnd
    ' Insert the linked table.
    Set fld = rng.Fields.Add(Range:=rng, Type:=wdFieldLink, _
        Text:=fieldText, PreserveFormatting:=True)
    Set rng = fld.Result
    rng.Collapse Direction:=wdCollapseEnd
End Sub

Open in new window

0
 
LVL 18

Expert Comment

by:xtermie
ID: 41858619
Another option, simpler, if you want to add specific cell data into specific cells in the Word table is to create a mail merge document.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question