PDA

View Full Version : Solved: SendKeys Will Not Work in Word 2007?



Ice-Tea-Jan
11-04-2011, 03:40 PM
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/ (wlmailhtml:{F6762D68-9658-403B-A89D-53AA3F13B7F8}mid://00000121/!x-usc: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

macropod
11-05-2011, 01:53 AM
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).

Ice-Tea-Jan
11-05-2011, 06:22 AM
Thanks MacroPod,

Still confused.:dunno

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

Please advise.

Janet

macropod
11-05-2011, 06:33 AM
Hi Janet,

It should be fixed. Have you tried it? Your macro works for me (but I use Word 2010 these days).

Tinbendr
11-05-2011, 08:00 AM
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"

Ice-Tea-Jan
11-05-2011, 09:44 AM
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.:think:

Janet

Ice-Tea-Jan
11-07-2011, 10:50 AM
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:doh:

macropod
11-07-2011, 03:43 PM
Hi Janet,

Sendkeys in Office 2007 did work for me before I upgraded to Office 2010.

Ice-Tea-Jan
11-07-2011, 08:29 PM
Macropod,

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

Janet

macropod
11-08-2011, 12:43 AM
Did you use SendKeys in conjunction with the InsertCrossReference Dialog box when you were in Word 2007?

Yes, see: http://www.eggheadcafe.com/microsoft/Word-Menus-Toolbars/35274667/crossreference-dialog-box--change-the-default-settings.aspx

See also: http://www.vbaexpress.com/forum/archive/index.php/t-35967.html
and:
http://www.tech-archive.net/Archive/Word/microsoft.public.word.docmanagement/2008-08/msg01111.html

Ice-Tea-Jan
11-08-2011, 10:29 AM
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. . .

Frosty
11-08-2011, 02:40 PM
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.

macropod
11-13-2011, 12:58 AM
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.

Ice-Tea-Jan
01-11-2012, 04:20 PM
Janet