Results 1 to 11 of 11
  1. #1
    Star Lounger
    Join Date
    Sep 2010
    Location
    Southern California
    Posts
    52
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Using VBA to assign a SEQ number

    I'd like to write a "macro" to assign a beginning SEQ number at run time.
    Situation: When creating a "Response to Interrogatories" from a template, the dialog box asks for the Interog number to start.
    How can I include that number in my macro so that when they generate the SEQ number (already defined in the template) it starts at that number.

    Thanks.
    Charlotte
    Char Q
    Pacific NW

  2. #2
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts
    Assuming that the first field contains the SEQ code which you want to set, use switch \rx as your default. The following macro code will set the first number to 8. Modify as necessary to use your dialog box result instead of 8.

    ActiveDocument.Fields(1).Code.Text = Replace(ActiveDocument.Fields(1).Code.Text, "\rx", "\r8")

  3. #3
    Star Lounger
    Join Date
    Sep 2010
    Location
    Southern California
    Posts
    52
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Richard, I think you're on to something...but this isn't enough for me. I did exactly what you suggested, but my number is "0" Can you give me more?
    Char Q
    Pacific NW

  4. #4
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    Willow Grove, Pennsylvania, USA
    Posts
    205
    Thanks
    4
    Thanked 49 Times in 40 Posts
    After you run the macro, you have to select everything (Ctrl+A) and update the fields (F9). Alternatively, you can have the macro update the fields; put the statement

    ActiveDocument.Fields.Update

    after the line that changes the field codes.

  5. #5
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts
    Char, if updating the fields (using the method jjfreeman suggested) did not give you the desired results, let me know and I'll post more of the code that I used for testing. (I didn't save it, but will happily recreate if you need additional help.)

  6. #6
    Star Lounger
    Join Date
    Sep 2010
    Location
    Southern California
    Posts
    52
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Richard: Yes, more code would be helpful. What I had in my head (though don't know the VBA to make it happen) was at the time the pleading is generated, the opening dialog box asks for the beginning number. Now, how to "pass" that number to a macro... not sure it can even be done.
    thank you so much!!
    Char Q
    Pacific NW

  7. #7
    Star Lounger
    Join Date
    Sep 2010
    Location
    Southern California
    Posts
    52
    Thanks
    1
    Thanked 0 Times in 0 Posts
    jjFreedman: a very interesting thing has happened. My F9 key is locking the document created based on my template?! This was not intentional and I cannot for the life of me figure out how this happened. It is happening to anyone who uses my templates, when the press F9 to update fields, the document is locking. Any ideas what happened??? I've loved for assigned keyboard shortcuts in the template and there are none.
    Char Q
    Pacific NW

  8. #8
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts
    Document SEQ.docm is attached.
    Attached Files Attached Files

  9. #9
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    Willow Grove, Pennsylvania, USA
    Posts
    205
    Thanks
    4
    Thanked 49 Times in 40 Posts
    I just saw the other thread where you found the macro causing the problem. Never mind!

    Quote Originally Posted by charq52 View Post
    jjFreedman: a very interesting thing has happened. My F9 key is locking the document created based on my template?! This was not intentional and I cannot for the life of me figure out how this happened. It is happening to anyone who uses my templates, when the press F9 to update fields, the document is locking. Any ideas what happened??? I've loved for assigned keyboard shortcuts in the template and there are none.
    To find out what command is assigned to the F9 key, open Word and press Ctrl and Alt and the plus sign on the number pad all at once, so the cursor turns into a cloverleaf shape; then press F9. That should open the Keyboard Shortcuts dialog, with the assigned command shown in the Commands box. (Check each of the templates listed in the Save In dropdown.) The command shown should be UpdateFields. If it's anything else, close the dialog and then go through the Options > Customize path to reassign F9 to that command.

    Also, there's a second default shortcut assigned to the UpdateFields command: Alt+Shift+U. Does that work to update fields?
    Last edited by jjfreedman; 2013-06-18 at 21:22. Reason: Just saw other thread

  10. #10
    Star Lounger
    Join Date
    Sep 2010
    Location
    Southern California
    Posts
    52
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Richard, not I had not seen the attachment. Thank you!! I'll need to look at it later today...off and running.
    Char Q
    Pacific NW

  11. #11
    Star Lounger
    Join Date
    Sep 2010
    Location
    Southern California
    Posts
    52
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you, JJ. This information IS helpful, however.!
    Char Q
    Pacific NW

Posting Permissions

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