Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2006

Tip: Looking for answers? Try searching our database.

help with automating letter

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
colm o'brien - 21 Apr 2006 12:05 GMT
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
Greg Maxey - 21 Apr 2006 13:07 GMT
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
colm o'brien - 21 Apr 2006 16:25 GMT
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

> Colm,
>
[quoted text clipped - 26 lines]
> End If
> End Sub
Greg Maxey - 21 Apr 2006 17:31 GMT
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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.