Results 1 to 12 of 12
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Fishburn, Durham, England
    Posts
    125
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help - trying to automate a template (2000/SR-1)

    Hello All,

    Hopefully this will be an idiotic posting. I am trying to automate a template for my colleagues at work (before I move on to another job!). I can't seem to get it to work, though I'm sure I've followed everything (in principal) that is shown in the example from Chapter 34 Special Edition Using Word 2000. Can anyone tell me what I've done wrong? I don't know what the error codes mean and I have been driving myself crazy today trying to figure this out. All help greatly appreciated. I've attached a sample of my document.
    Attached Files Attached Files

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help - trying to automate a template (2000/SR-1)

    You've inserted references to bookmarks and the bookmarks themselves DO NOT exist!

    Try just inserting bookmarks, not references to the bookmarks.

    One purpose of the references is to have the contents of a bookmark display at another location in the document. But you first need the bookmark. Make sense?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,048
    Thanks
    124
    Thanked 119 Times in 116 Posts

    Re: Help - trying to automate a template (2000/SR-1)

    Hi Susan,

    Haven't looked at your document yet, maybe later tonight. Based on Kevin's remarks, are you by chance using ASK fields to gather information? If so, run the ASK fields in your template and they will generate the bookmarked entries. It has been many moons since I did anything with these, but it seems to me that you may need an AutoNew macro that updates the fields. For some examples of using such fields (as well as using a UserForm) take a look at the ASK field and Userform tutorials that you can get from <A target="_blank" HREF=http://www.addbalance.com/word/download/index.htm> my download page</A>.

    For more on fields and their use, follow the links at . You may also want to take a look at some of the UserForm information on the <A target="_blank" HREF=http://www.mvp.org/word> MVP website.

    Hope this helps,
    Charles Kyle Kenyon
    Madison, Wisconsin

  4. #4
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Fishburn, Durham, England
    Posts
    125
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help - trying to automate a template (2000/SR-

    Thanks. I will certainly look at your tutorials - I find it fasinating. Anyway, I started out by trying to use ASK fields, putting them in
    at the top of the document template, but it only 'ran' them before I tried to print - which wouldn't be useful for the people trying to use
    the template. So that was when I looked towards using a user form - knowing nothing about VBA as you have probably gathered.

    Anyway, I will have a look at your tutorial and try again!

    Thanks for your suggestions.

  5. #5
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Fishburn, Durham, England
    Posts
    125
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help - trying to automate a template (2000/SR-

    Thanks -- I've finally worked this one out and the template works great - on my machine. If someone from work using Office 97 (everyone else) tries to use the template the form runs, but it doesn't fill in any of the bookmarks. It does mark the fact that the bookmarks are there.

    Any further suggestions?

  6. #6
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help - trying to automate a template (2000/SR-

    At this point you'll have to post code soze we can take a look.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  7. #7
    BAM
    Guest

    Re: Help - trying to automate a template (2000/SR-

    Hi Susan,

    How did you insert the Bookmarks? Did you use Insert/Bookmark? What I see on my end are only 3 bookmarks: bkAddress, bkAddressee, and bkSubject.

    Now I do see your other bookmark names in field braces, e.g. {bkAddressee}, but only Bookmark placeholders for the 3 bookmarks I previously mentioned. (To view the placeholders use Tools/Option/View and turn on Bookmarks)

    Note too that these extra fields will result in errors since the reference to the Bookmark isn't really being used in field that Word recognizes.
    ~~~~~~~~~~~~~
    Cheers! <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  8. #8
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Fishburn, Durham, England
    Posts
    125
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help - trying to automate a template (2000/SR-

    Right - here's the macro that I adapted from the Special Edition Using Word 2000 -
    Private Sub Document_New()

    With frmLetterData
    .ClientRefAns = ""
    .OurRefAns = ""
    .AddressAns = ""
    .AddresseeAns = ""
    .SubjectAns = ""
    .OurRefAns.SetFocus
    End With

    frmLetterData.Show

    If btnOKClicked = True Then
    Bookmarks("ClientRef").Range.Text = frmLetterData.ClientRefAns
    Bookmarks("OurRef").Range.Text = frmLetterData.OurRefAns
    Bookmarks("Address").Range.Text = frmLetterData.AddressAns
    Bookmarks("Addressee").Range.Text = frmLetterData.AddresseeAns
    Bookmarks("Subject").Range.Text = frmLetterData.SubjectAns
    With ActiveDocument.ActiveWindow.View
    .ShowBookmarks = False
    .ShowAll = False
    End With
    Else
    ActiveDocument.Close wdDoNotSaveChanges
    End If


    End Sub

    - and attached is my updated template with the bookmarks named. I still can't get it to work and fear I may have to give up! (Though I've just ordered a book on visual basic from Amazon so we'll see!

    As always any help greatly appreciated.
    Attached Files Attached Files

  9. #9
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Fishburn, Durham, England
    Posts
    125
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help - trying to automate a template (2000/SR-

    Thanks for your help - I didn't have the bookmarks inserted properly before. I think they are there correctly now and I attached a new file to my other reply post I made today. My template now works - but only when I am in the template itself! If I create a new document based on the template it brings up the form and seems to handle it ok, but doesn't put the bookmarks in when its finished running. If I go to insert bookmarks, it does list the bookmarks and when I show bookmarks they appear where they are supposed to be.

    Sometimes I hate being an amateur!

  10. #10
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Help - trying to automate a template (2000/SR-

    May I be so bold as to "re-write" the Special Edition example more to my liking. Consider it a free lesson in KevinCode -- for what it's worth.

    Attached find your document updated to work as you expect.

    Studying the technique will be far more helpful than back and forth volleys of post snippets. Feel free to ask "Why do you do it that way?"
    Attached Files Attached Files
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  11. #11
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Fishburn, Durham, England
    Posts
    125
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Why do you do it that way?

    Right, I have gone through your code and have the template partially working now. Perhaps you could help with the finishing touches.

    First of all, why when someone has missed a box say, does set cancel = true and why doesn't that make the form go away? I have had to comment this block out for now, as what I'm finding happens is that whatever has been filled in the boxes already (before going back to the reference that was missed) still gets put in the letter (ie, twice). I tried two things: putting a with statement in and re-initializing the form and although that cleared what had been entered into the form, the bookmarks still appeared twice. I also tried to set the bookmarks = ' ', but that caused an error in the code and it stopped running.

    Also the biggest difference I can see between 'Kevincode' and Special Edition code is the .Me in front of lots of things. Why is .Me used?

    Finally you declared CloseMode as an integer, but I don't see it used anywhere - what does it do?

    I hope I am not wasting your time. Thanks in advance for your patience.

  12. #12
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Why do you do it that way?

    Susan,

    >First of all, why when someone has missed a box say, does set cancel = true and why doesn't that make the form go away?

    The idea is if the user misses a required field, don't let the form close until they do!

    Setting the Query_Close event Cancel argument to True prevents the form from closing by definition. Please see the VBA help on QueryClose. The form will not go away unless Cancel stays False. I have raved about the use of Queryclose, and I still think it is one of the best events in VBA. It makes for cleaner, better understood code. Your Cancel button code (not to be confused with the QueryClose "cancel" argument) need only say Unload Me. The unloading thread calls the QueryClose event. If validations are in order, QueryClose ends (cancel = false) and the form closes. I love it. All forms should have a coded up QueryClose event.

    >Why is .Me used?

    The Me keyword is an abbreviation and a tool. It refers to "the specific instance of the class where the code is executing." In the case of forms, they are class objects containing control objects. Therefore, you can refer to the form as ME and dot notate your way to the controls and the form properties. By using ME instead of the actual form name, VBA incurs less overhead and executes more quickly (whose got the benchmarks, anyway?) than when using the class object name.

    As you see in the "Kevincode", making use of 'With me' makes the code easier to read and saves some execution overhead.

    >Finally you declared CloseMode as an integer, but I don't see it used anywhere - what does it do?

    CloseMode is the other QueryClose argument. It takes the value 0 thru 3 based on how the queryclose event was invoked. This statement:

    Unload me

    will set closemode = 1 (Again, see the VBA help). This gives you some flexibility in determining what action to take when the form is unloaded. For instance, if you are testing for closemode values (which I seldom do, BTW), you might halt the close event if the user clicked your Cancel Button or the Close item on the form's control menu and required values are not entered.

    If fBadData and (CloseMode = 1 or CloseMode = 0) then
    msgbox "Sorry Charlie, no tuna today. Please enter a valid name."
    Cancel = True
    'A nice thing to do here is to set focus to the control they left blank.
    me.txtFishName.setfocus
    else
    'Let the form close 'cause the user is shutting Word or Windows down!
    endif

    If the user is ignoring your form altogether and is shutting windows or Word down. Windows will try to close your form. If it does, closemode will equal 2 or 3 (depending on how they are trying to close). In that case, let the form close even if required values are left blank.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •