Click in Word to trigger Powerpoint?

  • Thread starter christophercbrewster via OfficeKB.com
  • Start date
C

christophercbrewster via OfficeKB.com

The system I've created lets an author of training material insert updateable
references to Powerpoint slides within a Word document. This saves a lot of
work for the material that we produce.

Now someone has requested the ability to use it in the classroom as follows:
the Word doc is displayed on his laptop and the Powerpoint is on the screen.
He would click on a slide reference in the Word document and that slide would
be displayed by Powerpoint.

My Powerpoint references are DOCVARIABLE fields. So clicking on the field
text would need to do two things at minimum: trigger an event, and give the
system something that would be passed to Powerpoint. Could clicking the field
trigger an event? I think it would need something added, such as the Alt key
or being following by an F key.

Alternatively, I could use the LINK field instead of DOCVARIABLE, since these
are made to be clicked, but the purpose seems to be only to insert material
at the link's location. I need it to return some information, not insert
something.

So: Does anyone know a way to make something clickable that would trigger a
Powerpoint action?

--
Christopher Brewster
Lockheed Martin, Eagan MN

Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/200902/1
 
J

Jay Freedman

I'm going to leave the PowerPoint part of the programming to you, because I'm
not clear on what you want it to do. The Word part of it is doable, though.

Start by making your "clickable object". To the left of one of your DOCVARIABLE
fields, type MACROBUTTON PPT . Select from the M to the end of the DOCVARIABLE
field and press Ctrl+F9 so you now have one field embedded in another:

{ MACROBUTTON RunPPT { DOCVARIABLE somename } }

When this field is updated, it will show the value of the document variable
(actually, the result of the DOCVARIABLE field). When you double-click this
field, it will launch the macro named RunPPT. (At the end of this post I'll
point out how to make it work with a single click.) Repeat for all the other
DOCVARIABLE fields -- they should all call the same macro.

Now write a macro named RunPPT (of course, you can use any non-reserved name for
the macro, and put the same name into the MACROBUTTON fields).

In the VBA editor, click Tools > References and check the reference for
"Microsoft PowerPoint Object Library" to make the PPT object model available in
Word VBA.

Assign an object to represent the running instance of PowerPoint (similar to the
code in http://www.word.mvps.org/FAQs/InterDev/ControlXLFromWord.htm), and
address all the PPT properties and methods you need by drilling down from that
object.

The information from the DOCVARIABLE field will be available in the RunPPT macro
as follows:

Dim ValueOfDocVariable As String
ValueOfDocVariable = Selection.Fields(2).Result

You can use this string to call any PowerPoint method you need to use.

For single-click operation, see the section "Double-click or single-click" in
http://www.word.mvps.org/FAQs/TblsFldsFms/HLinksInForms.htm.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.
 
C

christophercbrewster via OfficeKB.com

Thanks very much for your detailed answer. A couple of follow-up questions:

The DOCVARIABLE fields in my system are inserted by a macro activated by the
end user. Going on your description, each DOCVARIABLE field now needs to be
inside another field, but I'm not sure how to code this: would I add the
inner field and then construct the outer field around it, or add the outer
one and then insert the inner one within it? Or some other approach?

Getting the key information from the result text (that is, the slide number)
doesn't seem difficult, but is there a way to access the actual DocVariable
efficiently when the text is clicked?

--
Christopher Brewster
Lockheed Martin, Eagan MN

Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/200902/1
 
J

Jay Freedman

christophercbrewster said:
Thanks very much for your detailed answer. A couple of follow-up
questions:

The DOCVARIABLE fields in my system are inserted by a macro activated
by the end user. Going on your description, each DOCVARIABLE field
now needs to be inside another field, but I'm not sure how to code
this: would I add the inner field and then construct the outer field
around it, or add the outer one and then insert the inner one within
it? Or some other approach?

Look at the macro InsertHyperLinkFieldWithinMacroButtonField() in the middle
of http://word.mvps.org/faqs/macrosvba/NestedFieldsWithVBA.htm -- just
replace the hyperlink field code with the appropriate DocVariable field
code.
Getting the key information from the result text (that is, the slide
number) doesn't seem difficult, but is there a way to access the
actual DocVariable efficiently when the text is clicked?

It's much harder to get to the DocVariable itself than to get its value out
of the field. You'd have to get Selection.Fields(2).Code into a string,
remove the keyword DOCVARIABLE and the following space character, and use
what's left as the DocVariable's name so you can get its value. Why go to
all that trouble when the value is immediately available from the field's
..Result?

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
C

christophercbrewster via OfficeKB.com

Thanks. I had found that MVP page in the meantime and realized it was doing
what your description did manually. I thought there might be a way that
wasn't so much like recording from Word, but recording is just what I did. I
was also leaning toward your conclusion about getting the docvar value.

In both cases the solution doesn't quite seem "pure code" but uses the actual
text to create the new field and get the embedded field's value, but I'll go
with it.
 

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