Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Dec 2000
    Location
    Montreal, Quebec, Canada
    Posts
    115
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Saving a value to use across modules (Word 2000)

    Hi gang,
    In a template I am writing macros to switch pages from vertical to horizontal or vice versa. In my header and footer I have a shape. I need to select and resize the shapes. I know that I have to specify the shape number to resize them. When I create a new doc based on the template I know what the shape numbers are. I know how to use an integer (j and k) to identify these shapes. What I want to do is set the values for j and k to a default when I create a new file based on this template (j=3 and k=4) and then modify those values when I run the macro to switch to horizontal or vertical. I want to add 2 to j (j=j+2) and to k (k=k+2) and then use this value to identify the shapes in my new header and footer and resize them.
    What I can't do is set the default values to begin with and then keep incrementing these values every time I run the macro.
    You have certainly guessed that I am not a programmer. Help please!

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Saving a value to use across modules (Word 2000)

    If you declare a variable at the top of a standard module as

    Public j As Integer

    you can refer to it in any module in the same template. If you want to set an initial value, do that in an AutoExec macro.

    If you only want to use it in a single procedure or function, but let it keep its value across runs, declare it within the procedure or function as]

    Static j As Integer

  3. #3
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Saving a value to use across modules (Word 2000)

    When faced with a similar problem I simply gave the shapes names that I could use to locate them. This was done manually using the Immediate window in the Visual Basic editor
    Select the shape in the header then go to the immediate window and type
    Selection.ShapeRange(1).Name = "myPrivateShape"

    Later the macro can reference hdr.ShapeRange("myPrivateShape")

    Edited to add. We had another similar problem here in the lounge a few weeks ago, where we needed to find shapes in a particular header. The trick that time was to use Shape.Anchor.Inrange(hdr.Range) to see if the anchor for a shape was in a particular header.


    StuartR

  4. #4
    2 Star Lounger
    Join Date
    Dec 2000
    Location
    Montreal, Quebec, Canada
    Posts
    115
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Saving a value to use across modules (Word 2000)

    Hi Hans,
    I tried it. In the AutoNew macro that runs when creating a new doc based on the template I put Public j as integer
    I got an error message saying Invalid attribute in sub or function.
    What else I am missing?
    Thanks alot for your help.

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Saving a value to use across modules (Word 2000)

    A Public Dim needs to be outside the Sub. The top of the same module (code window) is a good place for it.

    Added: See Hans' original message for more details.

  6. #6
    2 Star Lounger
    Join Date
    Dec 2000
    Location
    Montreal, Quebec, Canada
    Posts
    115
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Saving a value to use across modules (Word 2000)

    It worked! Thank you, thank you, thank you.

Posting Permissions

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