help with automating letter

C

colm o'brien

i want to create a letter which when opened asks several questions and then
inserts relevant paragraphs dependent on answers

eg dialog box asks was sale advised
if yes paragrahed blahblah 1 inserted else blahblah 2 inserted

any ideas how i can do this it can't be from database
 
G

Greg Maxey

Colm,

Well without a database you are going to have to store the blah 1 and
blah 2 data either as another file or as AutoText. Then you are going
to need an autoopen macro that asks the questions or use a Userform
(preferred) see:
http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm
Then you will need to use a field or bookmark to mark the spot in the
document for data insertion.

Here is a small example. You create a pair of AutoText entries with
detailed instructions for doing what ever. For this example name them
goleft and goright. You create bookmark in the document where you want
the data to appear (call it Answer1). You create an autoopen macro
that asks the questions and inserts the appropriate text based on the
answer:

Sub AutoOpen()
Dim oDoc As Word.Document
Dim BMRange As Word.Range
Set oDoc = ActiveDocument
Set BMRange = oDoc.Bookmarks("Answer1").Range
If InputBox("Answer yes or no", "Question", "yes") = "yes" Then
BMRange.Text = oDoc.AttachedTemplate.AutoTextEntries("GoLeft").Value
oDoc.Bookmarks.Add "Answer1", BMRange
Else
BMRange.Text = oDoc.AttachedTemplate.AutoTextEntries("GoRight").Value
oDoc.Bookmarks.Add "Answer1", BMRange
End If
End Sub
 
C

colm o'brien

Thanks for that Greg it has helped a lot however

as the letter evolves i find that i want to ask a further question and if
the answer is yes i want to collect 6-7 pieces of information from the user
and place them in bookmarks

also i want this to be used by several users on the network how can i copy
the document and all macro's and autotexts to public folder if i copy letter
to public folder the macro doesn't run and the last inserted text appears.

sorry i'm new to this and probably will end up with more questions than
answers
 
G

Greg Maxey

Colm,

I would again suggest that you look into using a userform to gather all
of the data in advance.

Extending the AutoNew (to fire on new documents created from a
template, while AutoOpen fires when an existing docuement is opened)
macro to your question, you could do something like this:

Sub AutoNew()
If InputBox("Do you like beer?", "Question", "Yes") = "Yes" Then
AskMoreQuestions
Else
AskLessQuestions
End If
End Sub
Sub AskMoreQuestions()
Dim oDoc As Word.Document
Dim BMRange As Word.Range
Set oDoc = ActiveDocument
Set BMRange = oDoc.Bookmarks("Answer1").Range
BMRange.Text = InputBox("What kind of beer do you like?", "Type")
oDoc.Bookmarks.Add "Answer1", BMRange
Set BMRange = oDoc.Bookmarks("Answer2").Range
BMRange.Text = InputBox("How much beer do you like?", "Type")
oDoc.Bookmarks.Add "Answer2", BMRange
End Sub
Sub AskLessQuestions()
'Code similar to the previous macro
End Sub

For your second question, I have no network smarts. It seems to me
that if you publish your template to the network then all of the macros
will be available to user creating documents with that template.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top