PDA

View Full Version : Solved: Activating the currently active, but unknown PPT slide from Word or Excel



SherryO
02-06-2006, 07:45 AM
I need to copy and paste different things from different files. Part 1 of a Word doc, the last three slides of a PowerPoint presentation and two sheets of Excel data, etc. The thing is, the filenames are constantly changing, so I would like to just activate the active doc or ppt or xls. What are the commands to activate whatever is already active when switching from one app to the other? I could be calling it from any of the three, or I could have to throw Project into the mix as well. In case I'm not explaining it well, let me try again...
How do you activate the currently active Word doc from Excel?
How do you activate the currently active Excel sheet from Word?
How do you activate the currently active Word doc from PowerPoint?
How do you activate the currently active PowerPoint Slide from Word or Excel?
I realize that this is probably easy an I'm just dim, but any help would be appreciated.
Thanks!
SherryO

Ken Puls
02-06-2006, 10:03 AM
Hi SherryO,

I have a page on my site which demonstrates how to get at each of the applications you mention using Late Binding (http://www.excelguru.ca/XLVBA/XLVBA09.htm).

Any of these routines can be called from any other app, so the "Word Doc" will work from either Powerpoint or Excel.

HTH,

SherryO
02-06-2006, 01:09 PM
It's wonderful code, but unfortunately, I'm not sure how to use it for my project. I want to be able to go between the apps and copy/paste from whatever document happens to be open at the time. For example, I want to copy six slides from X ppt presentation into Y Word doc. I can only copy 1 slide at a time so how do I go back and forth between X and Y when I don't know what their filenames may be? I hope this makes sense. Perhaps I'm looking at it weird... Thanks!!!

Ken Puls
02-06-2006, 02:40 PM
Hi Sherry,

Filenames are not actually required, as the code will bind to the active instance of the application.

Try this:

-In Powerpoint select the slide you wish to copy in the window at left. (Make sure you click it there, as I have not tried to make this code any smarter than that.
-Make sure that your cursor is in the word document right where you want the slide.

Put this code in a powerpoint module and run it.

Sub PushToWord()
'Bind to an existing or created instance of Microsoft Word
Dim objApp As Object

'Attempt to bind to an open instance
On Error Resume Next
Set objApp = GetObject(, "Word.Application")

If Err.Number <> 0 Then
'Could not get instance, so create a new one
Err.Clear
On Error GoTo ErrHandler
Set objApp = CreateObject("Word.Application")
With objApp
.Visible = True
.Documents.Add
End With
Else
'Bound to instance, activate error handling
On Error GoTo ErrHandler
End If

'Copy PPT slide to Word
ActiveWindow.Selection.Copy
objApp.Selection.PasteSpecial

ErrHandler:
'Release the object and resume normal error handling
Set objApp = Nothing
On Error GoTo 0
End Sub

You'd have to do each slide seaparately though with this code, although it could be modified.

HTH,

SherryO
02-07-2006, 02:10 PM
This did it. Thank you very much!!

Ken Puls
02-07-2006, 10:26 PM
Glad to be of help! :)