Reply to topic  [ 1 post ] 
Merging data table into form document 
Author Message

Joined: 2006-03-12 12:32:47
Posts: 138
Since NWP lacks a Merge capability, I wrote this macro to merge data from a Data document into a Form document.

The Form document can have field names interspersed in the text. When you run the macro, it modifies the Form document by replacing each occurrence of a field name with the data value specified in a Data file.

The format of the Data file is a 2-column table with field names in the first column and data values in the second column.

You might want to save the Form document as a Nisus Template so you won't accidentally overwrite the original form when you perform the merge.

Here is the macro:

# Data table should have 2 columns:
# Field Name in 1st column. Data Value in 2nd column.

Prompt 'Data Table should be in front of Form document. No other window should be open. Otherwise, choose Stop.'

###

# Data table:

# Start with first Field Name cell:
Select All Document
Select Start
$KeepLooping = Select Table Cell 1, 1 # Returns True if selection succeeds.

While $KeepLooping

$field = Read Selection # Field name = first column.

# Select corresponding Data Value:
Select Relative Table Cell 0, 1
$data = Read Selection

Write Find Expression $field
Write Replace Expression $data
# Prompt "field = $field data = $data" # For debugging.

# Form document: Replace field name with data value:
Menu 'Exchange Front Windows'
Find and Replace $field, $data, '-iavW' # Case sensitive; All; Verbose; Wrap

# Data table: Select first column (field name) of next row:
Menu 'Exchange Front Windows'
$KeepLooping = Select Relative Table Cell 1, -1
# Returns False & exits loop if fails.
End


2008-01-03 00:05:17
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software