SendKeys problem with wdDialogInsertCrossReference

B

Brian Murphy

I have some code that works fine in Word 2003 for displaying notorious
Insert Cross Reference dialog. This is to display the dialog so as to
insert a cross reference to a Figure caption.
With Dialogs(wdDialogInsertCrossReference)
SendKeys "%t{home}ff"
SendKeys "{enter}"
SendKeys "%r"
SendKeys "{down}"
SendKeys "{enter}"
SendKeys "%w" 'move to list of references
rtn = .Display
End With

This code does not work in Word 2007. In Word 2003 the "ff" moves the
selection first to Footnote, and then to Figure. But in Word 2007 the
second "f" does not get done, and the selection is stuck on Footnote.
I have spent hours trying find something that works, but nothing does.

Does anyone know how to get this to work?

Thanks,

Brian Murphy
 
D

Doug Robbins - Word MVP

Try

With Dialogs(wdDialogInsertCrossReference)
SendKeys "%t"
SendKeys "fef"
SendKeys "{enter}"
SendKeys "%r"
SendKeys "{down}"
SendKeys "{enter}"
SendKeys "%w" 'move to list of references
rtn = .Display
End With

I am not sure what would be considered more notoriously unreliable, the
Cross Reference Dialog (which I consider does behave itself better in 2007
than it did in previous versions) or SendKeys.

--
Hope this helps,

Doug Robbins - Word MVP

Please reply only to the newsgroups unless you wish to obtain my services on
a paid professional basis.
 
B

Brian Murphy

Thanks for the suggestion, Doug.

I gave it a try, but the problem still remains. The selection is
still stuck on Footnote.

Did you try it yourself and it worked?
If so, what Application.Build of Word2007 are you using?

Brian
 
D

Doug Robbins - Word MVP

Yes, it did work here with Word 2007 (12.0.6514.5000) SP2 MSO
(12.0.6425.1000)

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
B

Brian Murphy

Well darn!
Do you have both Footnote and Figure in your list of available
reference types?

I have MSO SP2 from the following download
www.microsoft.com/downloads/details.aspx?FamilyID=b444bf18-79ea-46c6-8a81-9db49b4ab6e5&displaylang=en
Word tells me I've got
Word 2007 (12.0.6425.1000) SP2 MSO (12.0.6425.1000)

How can I get build 6514 of Word? I don't really expect it to make
any difference, but you never know.

When I manually do Insert/Cross Reference, I have to type "fef" slowly
to move the selection from Footnote, to Equation, to Figure. If I
type the "fef" quickly, the selection stays on Footnote.

Something wierd is going on. I've tried it on three different
computers with the same result. Grrrr!

Brian
 
D

Doug Robbins - Word MVP

As I had mentioned, my experience with Word 2007 is that the Insert Cross
Reference dialog behaves better than it did in previous versions where it
annoyed the hell out of me when I left the dialog open and wanted to insert
another cross reference, the focus would return to the top of the list.

As an alternative to using that dialog, you might consider creating a
userform that contained a listbox to display the type of reference items and
code to insert a cross reference based on the item selected from the
listbox.

Such a listbox can be populated using the following code in the initialize
statement of the userform

Dim afield As Field
Dim caplist As String
Dim i As Long
caplist = ""
For Each afield In ActiveDocument.Fields
If afield.Type = wdFieldSequence And InStr(afield.Code, "Figure") > 0
Then
If caplist = "" Then
caplist = "Figure " & afield.Result
Else
caplist = caplist & "|Figure " & afield.Result
End If
End If
Next afield
lstCap.List = Split(caplist, "|")


--
Hope this helps,

Doug Robbins - Word MVP

Please reply only to the newsgroups unless you wish to obtain my services on
a paid professional basis.
 
J

Jonathan West

Hi Brian

It may be that the problem is that you are using Word 2007 under Windows
Vista. Sendkeys is broken under Vista, which as far as I can tell appears to
be a deliberate act on the part of Microsoft. Goodness only knows why.

You might want to try using Karl Peterson's SendKeys replacement, which is
available here.
http://vb.mvps.org/samples/SendInput/

It is a module that you can drop into your VBA project and have it work
exactly as Sendkeys used to.
 
B

Brian Murphy

Thank you Doug and Jonathan for the suggestions.

I've been trying really hard to avoid resorting to a custom userform,
but it's just about come to that.

I've been testing in both XP and Vista, and I haven't noticed any
difference in behavior for my particular macros.

I'm sure you know this, but I'm trying to display the Insert Cross
Reference dialog with my choice of Reference Type pre-selected. So
that the user can select the item to be cross-referenced.

I think I'll give SendInput a try, but I'm not too optimistic. Then
it'll have to be a userform.

Have either of you tried Word 2007 in Windows 7? I have not. More
fun in the sun.

Brian

If you want to try or look at my code yourself, download these
files.
www.rotordynamics.org/public/murf_macros_for_Word_Documentation.pdf
www.rotordynamics.org/public/murf_macros.dot
I create lots of engineering reports and technical papers, and these
macros help me a lot.
If all you want to do is look at the code, put murf_macros.dot on the
desktop and use File/Open from inside Word to open it.
 
D

Doug Robbins - Word MVP

It's no more fun (nor less) in Windows 7 than it was in Vista of XP

--
Hope this helps,

Doug Robbins - Word MVP

Please reply only to the newsgroups unless you wish to obtain my services on
a paid professional basis.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top