Results 1 to 11 of 11
  1. #1
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Option Explicit (Eng/Word2K/SR-1a)

    Hi All:
    I have a macro that I copied which gives a compile error. I know that the reason is that I have Option Explicit set & this macro hasn't declared any variables. I have no idea, however, what the variable type should be for each variable. I usually just experiment until I get lucky.
    1. What should the DIM statements be for the macro below?
    2. What would be a good introductory book to determine this? <img src=/S/blush.gif border=0 alt=blush width=15 height=15><pre>Sub ToolTipName()
    ' ToolTipName Macro
    'submitted by Bill Shack, Dec 2000

    ' The toolbar (command bar).
    barName = InputBox("Enter the toolbar name", "Bar", "")
    With CommandBars(barName)

    ' The custom control.
    buttonName = InputBox("Enter the button name", "Button", "")
    With .Controls(buttonName)

    ' The ToolTip to change or set.
    tipText = InputBox("Enter the Tooltip", "Tip", "")
    .TooltipText = tipText

    End With
    End With

    End Sub</pre>

    Thanks in advance.

  2. #2
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Option Explicit (Eng/Word2K/SR-1a)

    barName as string
    buttonName as string
    tipText as string

    or they can all be variants as well.
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  3. #3
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Option Explicit (Eng/Word2K/SR-1a) - Thanks

    Thanks to both of you. Howard, I assume you meant to say to always use Option Explicit unless someone is paying you NOT to use it. In any event, no one will be paying me to write macros unitl I learn how. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

  4. #4
    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: Option Explicit (Eng/Word2K/SR-1a)

    The Object Browser (F2) gives the var type at the bottom. (The position of these panes might be configurable, so maybe yours will appear somewhere other than the bottom.) It also should be in the help file in the entry for that property.
    Attached Images Attached Images

  5. #5
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Option Explicit (Eng/Word2K/SR-1a)

    Option Explict means yo uhave to declare the variables.
    No need to specify any type.

    In your case, they likely should be strings.

    P.S. Do NOT ever use code without Option EXplicit unless someone is paying you to use the code with OUT Option EXplicit.

    Most any VBA or VB book will explain Option Explicit.
    I would suggest Steve Roman's Writing Word Macros (ISBN: 1 565927257).

  6. #6
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Option Explicit (Eng/Word2K/SR-1a) - Thanks

    I've been distracted preparing a contract to send to a Client, hopefully, there are no typos, etc. in the contract.

  7. #7
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Option Explicit (Eng/Word2K/SR-1a)

    Thanks, Jefferson. That will be useful for determining the variable type in the future (so long as I can figure out what the object is <img src=/S/smile.gif border=0 alt=smile width=15 height=15>).

  8. #8
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Option Explicit (Eng/Word2K/SR-1a)

    In most cases, you can determine the object by looking at the Help for the Method/Property returning the value.

    Note: Get into the habit of NOT using Variants to reduce grief when the time comes to import your code to a VSA version of Office.

  9. #9
    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: Option Explicit (Eng/Word2K/SR-1a)

    I did a search within the object browser; certainly I was not aware that there was a VBA.Interaction object or collection or whatever!

  10. #10
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Option Explicit (Eng/Word2K/SR-1a)

    Hi Jefferson:
    I'm confused. I thought that your <post#=172036>post 172036</post#> meant that I could use the object browser when trying to determine the variable type. I may have used the wrong term when I said object.

  11. #11
    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: Option Explicit (Eng/Word2K/SR-1a)

    Or maybe your use of "object" was a pun and I just didn't get it? In brief, I thought you were referring to possibly having to know the information in the left pane, the object tree, before being able to find the info about a specific property or method. Due to the search feature, you don't have to know that, you can quickly click through each of the search results, and the relevant info will be displayed for each object that has a similarly named method or property. They don't vary much and, if they do, the context should become obvious upon closer examination... or use of the F1 key. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

Posting Permissions

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