Results 1 to 2 of 2

Thread: VBA

  1. #1
    2 Star Lounger rjbphillipsiii's Avatar
    Join Date
    Mar 2003
    Memphis, Tennessee, USA
    Thanked 0 Times in 0 Posts
    If anyone could assist me with a simple toggle Macro, when you run it the first time it would set a value in the computer memory anything will do.
    First it would preform a function/command after which it would set the memory variable. When the Macor was run again I think using the IF THEN ELSE
    it would see the Macro needs to go to the second selection preform the function/command and reset the value to 0 or nothing. Then when the Macro was rung again it would run the first section again and set the value or variable back to something like a 1 ????
    Hope you can understand a litte or what I am trying to say?
    R.J.B. Phillips III
    Logical Systems Inc. Part Time Drafter
    IBC WONDER HOSTESS Retired 33+ years
    Firestone Tr & Rubber Company 15 Years

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Silicon Valley, USA
    Thanked 94 Times in 90 Posts
    Quote Originally Posted by rjbphillipsiii View Post
    If anyone could assist me with a simple toggle Macro...
    Would this be a Word macro, a macro in another Office application, or another host entirely? (I'm going to move this to the appropriate forum based on your answer.)

    In most cases, variables you set in VBA in a host application such as Word are not persistent. However, if you declare a global Public variable (at the top of the module, outside of any Sub or Function), then it should remain in memory as long as the code module itself is active. VBA also has the concept of a Static variable, which retains its value between executions of a procedure, and is private to that procedure. One of these might fit your needs.

    For something a bit more permanent, if your host is Word, you could use Document Variables or Document Properties to store a value. Document variables are not visible to the user, so they are fairly safe from tampering, if that is a concern for your application.

    I realize this is a very general answer, but hopefully I've gotten you a bit closer to a solution.

Posting Permissions

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