Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    May 2002
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Select reference from list (Word2000 sr1a)

    I know almost nothing about VBA, and would like to create a macro to override some Word defaults when inserting cross references. I have used the macro recorder and got the following code:

    Sub CrossRef1()
    '
    Selection.InsertCrossReference ReferenceType:="Figure", ReferenceKind:= _
    wdOnlyLabelAndNumber, ReferenceItem:="8", InsertAsHyperlink:=True, _
    IncludePosition:=False
    End Sub

    The settings for the reference are correct, but the statement ReferenceItem:="8", inserts the specific reference number 8 from the list. The question of course is:

    How do I code it so that I can select a reference from the list <img src=/S/question.gif border=0 alt=question width=15 height=15>

  2. #2
    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: Select reference from list (Word2000 sr1a)

    Well, it's a tough one for your first outing...

    The code you got shows Word implementing the results of a selection made in the dialog, and not how to pop up the dialog for the user. You can display the Insert Cross Reference dialog this way:

    With Dialogs(wdDialogInsertCrossReference)
    ' Set up what the user will see (doesn't always work)
    .Show
    End With

    Most dialogs in Word have a single action: you make your choices and click OK (or whatever). This returns control to your macro before doing anything else so you can inspect the user's choices and modify them before executing the action of the dialog. The Insert Cross-Reference dialog, however, lets the user take multiple actions before closing the dialog. Thus, the usual strategy of .Display, then do stuff, then .Execute, doesn't work in this case, and you really don't have much control from what I can see.

    What kind of behavior(s) are you trying to override? Maybe those more experienced with cross-referencing stuff will have suggestions.

  3. #3
    New Lounger
    Join Date
    May 2002
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Select reference from list (Word2000 sr1a)

    I didn't want it to be a tough one... <img src=/S/sigh.gif border=0 alt=sigh width=15 height=15>

    Basically the default cross reference is to insert the 'entire lable and text' , whereas I always want just the 'only label and number' format. Whenever I switch between table and figure cross references, it resets the default to entire caption, and also resets the highlighted entry to the 1st reference in the list. Also, after selecting a cross reference, the window does stay open, but if I click on it again to make it active it again resets the selected reference to the 1st in the list, which is annoying when I need to set up multiple cross references to the same item.

    So basically I was hoping to run individual macros to insert figure and table cross references, with only label and number as defaults, to save a mouseclick or two.

  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 : Select reference from list ( Word2000 sr1a )

    I guess I'd be inclined to let the dialog do what it likes, and run a "clean-up" macro afterwards that changes the settings in the individual cross-references to match the shorter format that you want. I haven't tried to do this, but I think it should be possible.

  5. #5
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Select reference from list (Word2000 sr1a)

    Hi,
    Unfortunately the usual methods for setting dialog box arguments don't seem to work in this case - see MSKB article Q209668 for details (unfortunately, their workaround involves SendKeys, which is, IMHO, an abomination! <img src=/S/grin.gif border=0 alt=grin width=15 height=15>)
    HTH.
    Regards,
    Rory

    Microsoft MVP - Excel

  6. #6
    New Lounger
    Join Date
    May 2002
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Select reference from list (Word2000 sr1a)

    Thanks for the tip. I don't know enough about SendKeys to mistrust it, and following the MSKB advice I got the cross reference menu working exactly as I want it: popping up with my preferences already selected.

    Hooray for SendKeys! (And the Woody's Lounge!)

Posting Permissions

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