Consulting

Results 1 to 14 of 14

Thread: Solved: SendKeys Will Not Work in Word 2007?

  1. #1

    Question Solved: SendKeys Will Not Work in Word 2007?

    Hello,

    I’m unsure how to update this macro for Word 2007 (Word/Window/VBA {version/build/Service Pack} specifics are below).

    It worked fine in Word 2003 via preselecting the cross-reference dialog box (for Table, etc.) so one simply makes a final selection in the variable area.

    I’ve been studying this “SendKey” issue, and the in the link http://vb.mvps.org/samples/SendInput/ it states “. . . in order to use the original SendKeys, you'll then have to prefix it with VBA.”

    That sounds simple, but this newbie is confused.

    Can somebody offer a solution (refitting this macro, or some OTHER VBA code) that will accomplish the same task?

    Always appreciative of any help/insight.

    Janet


    Sub CrossReferenceTable ()
    '
    With Dialogs(wdDialogInsertCrossReference)
    SendKeys "%t" '(Alt + T): To get to Reference {T}ype
    '
    SendKeys "+(table)" 'Holds down shift to enter ALL letters (in case there is a "tabl{a}" caption that could roll out first
    '
    SendKeys "{enter}" 'Enters parameters for the Reference Type
    '
    SendKeys "%r" '(Alt + R): To get to Insert {R}eference
    '
    SendKeys "{down 1}" 'Selects "Only Label & Number" from pre-defined drop-down list
    '
    SendKeys "{enter 1}" 'Enters parameters for Insert Reference
    '
    SendKeys "%h" '(Alt + h): To get to {H}yperlink
    '
    SendKeys "+{+}" '(Selects hyperlink checkbox -- even it if is already on -- does not toggle to and fro!
    '
    SendKeys "{enter 2}" ' Enters parameters for hyperlink, & brings you to the {variable} area which end-user selects
    '
    .Show
    '
    End With
    '
    '
    End Sub


    Version Specifics, etc.:

    Word 2007:
    · MS Office Word 2007 (12.0.6545.5000) SP2 MSO (12.0.6545.5004)

    MS Windows
    · MW Windows Version 5.1 (Build 2600.xpsp_sp3_gdr.101209-1647:Service Pack 3)

    Visual Basic:
    · VBA: Retail 6.5.1040
    · MS Visual Basic 1987-2006
    · Version 1040
    · Forms3: 12.0.6415.100
    "If" is a big word.

  2. #2
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,433
    Location
    Hi Ice-Tea-Jan,

    When Office 2007 originally came out, SendKeys was not supported. Thankfully, MS responded to negative feedback about this and re-instated it in SP1 (and maybe even earlier).
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3

    MacroPod --Shouldn't SP2 & SP3 encompass SP1 fixes?

    Thanks MacroPod,

    Still confused.

    I have SP2 (for Word) and SP3 (for Windows). Shouldn't that encompass the SP1 "fix"?

    Please advise.

    Janet
    "If" is a big word.

  4. #4
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,433
    Location
    Hi Janet,

    It should be fixed. Have you tried it? Your macro works for me (but I use Word 2010 these days).
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #5
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    992
    Location
    Quote Originally Posted by Ice-Tea-Jan
    in order to use the original SendKeys, you'll then have to prefix it with VBA.”

    That sounds simple, but this newbie is confused.
    VBA.SendKeys "%t"

    David


  6. #6

    Tinbender and Macropod

    Macropod:
    It does still does not work (even as I am using SP2).

    Tinbender:
    Yes, I too thought it was simply placing VBA. ahead of the SendKeys -- but that did not work either.

    It is supposed to roll down to the "Table" selection; and yes -- I made sure the document had tables in which to cross-reference to.

    It brings up the dialog box, but does not make appropriate selections.

    I'll try it again, and report back later.

    Janet
    "If" is a big word.

  7. #7

    Works in Word 2010, not in Word 2007

    Macropod:

    Yep, it works in 2010; but unfortunately, I need to have it work within 2007.

    I'm reading about numerous issues/quirks with SendKeys, and also with the Cross Reference Dialog Box.

    Can anybody offer workaround sample?

    Janet
    "If" is a big word.

  8. #8
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,433
    Location
    Hi Janet,

    Sendkeys in Office 2007 did work for me before I upgraded to Office 2010.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  9. #9

    Macropod

    Macropod,

    Did you use SendKeys in conjunction with the InsertCrossReference Dialog box when you were in Word 2007?

    Janet
    "If" is a big word.

  10. #10
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,433
    Location
    Quote Originally Posted by Ice-Tea-Jan
    Did you use SendKeys in conjunction with the InsertCrossReference Dialog box when you were in Word 2007?
    Yes, see: http://www.eggheadcafe.com/microsoft...-settings.aspx

    See also: http://www.vbaexpress.com/forum/arch...p/t-35967.html
    and:
    http://www.tech-archive.net/Archive/.../msg01111.html
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  11. #11

    Forgive me Macropod, but still confused . . .

    The first link you provided refers to coding used in Word 2003 (not 2007). (I tried that macro anyway; and it did not work.)

    The second link deals with inserting hyperlinks. (Not sure of Word version, but it doesn’t appear to involve cross-referencing anyway.)

    The third link deals with inserting fields. (Not sure of Word version, but it doesn’t appear to involve cross-referencing anyway.)

    I wished for some coding/workaround for Word 2007 using the insert cross-reference dialog box.

    Any insight is appreciated. . .
    "If" is a big word.

  12. #12
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    Your macro doesn't work on my version of Word 2007. However, maybe it's a good time to step back. Sometimes trying to "solve the solution" creates more headaches than it is worth. Are you trying to solve the issues of SendKeys in Word2007? Or are you trying to figure out a way to insert a specific type of cross-reference in a specific type of document?

    What is it that you really want to have happen? I have 2 guesses, from the thread:
    1. You want to set "defaults" using the native Cross-References dialog in order to more efficiently insert (one or multiple) cross-references in a document which already has tables and captions for those tables, while still allowing your end-users to insert cross-reference which aren't, as an example, hyperlinks.

    2. You want to streamline the process of inserting particular types of cross-references in a document which already has tables and captions for those tables.

    The "real" solution (version independent) is to recreate the Cross-References dialog yourself (not terribly difficult, especially if you are only dealing with one particular available functionality-- I did it for numbered paragraphs, and didn't provide the ability for Tables with captions, but that would simply be more work). But that's really only necessary if your desire is #1 (and you can leave out the "hard" parts of dealing with all the options in main dialog.

    If your desire is the solution to #2, the answer is really simple.

    Simply create your own dialog which lists all the tables with captions in your document... allow the user to select one of those tables, and click the insert button... and then use the Selection.InsertCrossReference method, setting the various parameters (such as, InsertAsHyperlink:=True) in the settings you want.

    Otherwise, you'll simply need to offer the more robust solution of re-creating the dialog.

    But you've already (I assume) spent a lot of time trying to find the magic bullet... and it appears that there may not be one (for whatever reason-- service pack, MS bug relating to the xref built-in dialog, etc).

    So start working on the "real" solution: presenting an interface which allows your users to do what they want to do (insert a cross-reference to a captioned table).

    As you begin that process... please ask some questions to help you along. If I had the ready made solution, I would certainly present it-- but I don't. It looks like a bit of work, but not a ridiculous amount.

  13. #13
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,433
    Location
    Quote Originally Posted by Ice-Tea-Jan
    The first link you provided refers to coding used in Word 2003 (not 2007). (I tried that macro anyway; and it did not work.)

    The second link deals with inserting hyperlinks. (Not sure of Word version, but it doesn’t appear to involve cross-referencing anyway.)

    The third link deals with inserting fields. (Not sure of Word version, but it doesn’t appear to involve cross-referencing anyway.)

    I wished for some coding/workaround for Word 2007 using the insert cross-reference dialog box.

    Any insight is appreciated. . .
    They were all developed with Word 2007 on Windows Vista... The fact the target platform may have differed is immaterial.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  14. #14

    I marked solved -- Thanks to all that replied!

    Janet
    "If" is a big word.

Posting Permissions

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