1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Word 2003 - Simple automation - Guru help !

Discussion in 'Business Applications' started by shaygate, Apr 1, 2010.

Thread Status:
Not open for further replies.
Advertisement
  1. shaygate

    shaygate Thread Starter

    Joined:
    Mar 29, 2002
    Messages:
    158
    I have created a document for our engineers to use, as I am pretty much a VBA virgin I have been playing around with adding some simple automation and have run into a problem thats beyond my solving so I am asking you gurus out there !

    In the document i have created a UserForm that starts as the document is opened (the document is in Print Layout View) , into some textboxes they type their Name, Date, and Project Name. on hitting the OK button the VBA goes to a series of bookmarks imbeded in the document using the commands

    ActiveDocument.Bookmarks("name1").Select
    Selection.InsertBefore Text:=TextBox2


    and inserts the text from the user form, this is repeated for each catagory at different places in the document .... nice and simple.

    However two of the date bookmarks are inside footers (two different sections) and when the routine is finished instead of returning home (ActiveDocument.Bookmarks("home").Select) to the start and remaining in Print Layout View the cursor remains in one of the footers and the document is in "Normal view"

    Why is this happening and how can I stop or fix it ?, its obviously related to the bookmarks being inside a footer but why change the layout as well !! :confused:

    Ian
     
  2. Rollin_Again

    Rollin_Again

    Joined:
    Sep 4, 2003
    Messages:
    4,912
    Please post all of your code.

    Rollin
     
  3. shaygate

    shaygate Thread Starter

    Joined:
    Mar 29, 2002
    Messages:
    158
    Sorry its taken me a few days to respond, I was away for the Easter break.

    Here is the code as requested though it will show the same as I explained in my original post.

    Private Sub CommandButton1_Click()
    ActiveDocument.Bookmarks("name1").Select
    Selection.InsertBefore Text:=TextBox2
    ActiveDocument.Bookmarks("name2").Select
    Selection.InsertBefore Text:=TextBox2

    ActiveDocument.Bookmarks("date1").Select
    Selection.InsertBefore Text:=TextBox4
    ActiveDocument.Bookmarks("date2").Select
    Selection.InsertBefore Text:=TextBox4
    ActiveDocument.Bookmarks("date3").Select
    Selection.InsertBefore Text:=TextBox4
    ActiveDocument.Bookmarks("date4").Select
    Selection.InsertBefore Text:=TextBox4

    ActiveDocument.Bookmarks("project1").Select
    Selection.InsertBefore Text:=TextBox3

    ActiveDocument.Bookmarks("home").Select

    Unload UserForm1


    End Sub


    As you can see its all driven off the single command button, The bookmarks are set manualy in the base document and not by code.

    Date3 & Date4 are the entries in the footers, (2 different sections) and bookmark Home is on Page 1 and is just used to return the cursor to the start of the document.
     
  4. Rollin_Again

    Rollin_Again

    Joined:
    Sep 4, 2003
    Messages:
    4,912
    Try adding the lines below after inserting the last bit of text.

    Selection.HomeKey Unit:=wdStory

    ActiveDocument.ActiveWindow.View.Type = wdPrintView


    Rollin
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/914033

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice