PDA

View Full Version : Pulling info from field codes



tla
10-25-2007, 11:56 AM
OK, I have a task I want to accomplish that I have approached a couple ways and failed.

I have a table in a word document. It is 2 columns, one row. Above that table i have a list of words like so:
{MACROBUTTON Populate_Table System 1}
{MACROBUTTON Populate_Table System 2}
{MACROBUTTON Populate_Table System 3}
{MACROBUTTON Populate_Table System 4}
{MACROBUTTON Populate_Table System 5}


With the field codes toggled so only the System X is displayed. This is a test, in real life the system X would be replaced by acutal system names (which there are 20 or so).

When the system name is clicked, the Macro runs, and a line is added to the table in the document. This is the Macro


Sub Populate_Table()
mySystem = Selection.Text
ActiveDocument.Tables(1).Rows.Add
myRows = ActiveDocument.Tables(1).Rows.Count
ActiveDocument.Tables(1).Rows(myRows).Cells(1).Select
Selection.Text = mySystem
End Sub

Of course it popluiates the first cell of the new table row with an end of line box
How can i get the name of the system (which is variable in length) into the mySystem variable ? I tried passing a variable to the subroutine
{MACROBUTTON Populate_Table(1) System 1}
{MACROBUTTON Populate_Table(2) System 2} etc
but that doesn't seem to work.

tla
10-25-2007, 12:00 PM
X

tla
10-25-2007, 12:25 PM
As an addendum - the way i REALLY wanted to do this was to have the macro run when the person clicked "ADD" (macrobutton) and have a drop down box next to that add button with a list of system names. I ran into a roadblock because I don't want the whole document to be form protected as they have to do a lot of typeing and editing in the document as a matter of course. There doesn't seem to be a way to have dropdown box without the entire document being form proected. Is there a way to protect a section of the document for forms (to get the drop down functionality) but leave the rest of the document normal?

fumei
10-25-2007, 01:14 PM
You can isolate protected sections using a Continuous Section break.

Are you using Option Explicit? Your variables are not declared.

I have no idea what you mean by: "with an end of line box"

Line box?

tla
10-26-2007, 05:24 AM
By line box I meant the end of line character (square), but I belive I have figured out how to get the data I need from the first method.
I tried to protect sections of the document with continous line breaks. With no breaks added the document returend 2 sections when i ran a macro to check. When I added a break it listed 3 sections. I then unproteted the entire document and ran a macro to protect each section - the drop down box did not function adn was not protected. Not sure what I am doing wrong there.

tla
10-26-2007, 05:26 AM
Sorry, what would be the correct code to protect and unprotect a single section of the document for forms?

fionabolt
10-26-2007, 06:10 AM
ActiveDocument.Sections(1).ProtectedForForms = False
ActiveDocument.Sections(2).ProtectedForForms = True