Consulting

Results 1 to 6 of 6

Thread: Solved: Activating the currently active, but unknown PPT slide from Word or Excel

  1. #1

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

    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

  2. #2
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi SherryO,

    I have a page on my site which demonstrates how to get at each of the applications you mention using Late Binding.

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

    HTH,
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  3. #3
    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!!!

  4. #4
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    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.

    [vba]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[/vba]

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

    HTH,
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  5. #5
    This did it. Thank you very much!!

  6. #6
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Glad to be of help!
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





Posting Permissions

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