Results 1 to 7 of 7
  1. #1
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    SetFocus back to Word (2002)

    Hi, I am wanting to automate the insertion of a PowerPOint Slide, and the resizing of it to the current margin limits... Recording these events with a macro I have got the following code:

    Sub insertSlide()
    'insert PPS and resize to current margins
    Dim s As Single
    s = Selection.PageSetup.PageWidth - Selection.PageSetup.LeftMargin _
    - Selection.PageSetup.RightMargin
    Selection.InlineShapes.AddOLEObject ClassType:="PowerPoint.Slide.8", _
    FileName:="", LinkToFile:=False, DisplayAsIcon:=False
    ' need to make Word window active again here
    With Selection.InlineShapes(1)
    .Select
    .LockAspectRatio = msoTrue
    .Height = 300
    .Width = s
    End With
    End Sub

    the problem is that I need to reset the focus to the word doc. I do this by clicking on the page away from the inserted powerpoint slide, but when recording the macro I am unable to do this.

    I have tried Windows(1).Activate, and setfocus, but I cannot get it to work... any ideas anyone out there?!
    Thanks,

    pmatz

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: SetFocus back to Word (2002)

    Try this. It doesn't set the focus back to the document, but uses the InlineShape object directly:

    With Selection.InlineShapes.AddOLEObject(ClassType:="Po werPoint.Slide.8", _
    FileName:="", LinkToFile:=False, DisplayAsIcon:=False)
    .LockAspectRatio = msoTrue
    .Height = 300
    .Width = s
    End With

  3. #3
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SetFocus back to Word (2002)

    Hi Hans,

    Well, that works a treat once i click off the slide. When i click off the slide it resizes and fills the page width.
    I am still perplexed as to how to set the focus back to word once i have done this.

    hold on...
    no.

    Selection.TypeParagraph doesnt work [img]/forums/images/smilies/sad.gif[/img]
    Thanks,

    pmatz

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: SetFocus back to Word (2002)

    The only workaround I can find is to create a floating shape first, and convert that to an inline shape:

    With ActiveDocument.Shapes.AddOLEObject(ClassType:="Pow erPoint.Slide.8", _
    FileName:="", LinkToFile:=False, DisplayAsIcon:=False, Anchor:=Selection.Range)
    .Select
    .LockAspectRatio = msoTrue
    .Height = 300
    .Width = s
    .ConvertToInlineShape
    End With

    Perhaps somebody else has a better idea.

  5. #5
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SetFocus back to Word (2002)

    Thanks Hans, that workaround is cool.

    I am going to try to learn how after doing this to open the MS PPS object and bring it to focus, but thats for another day !

    btw, i will paste that DB code this weekend. Have a good one yourself

    <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    Thanks,

    pmatz

  6. #6
    New Lounger
    Join Date
    Mar 2004
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SetFocus back to Word (2002)

    At the start make an declared object (mDoc as Document) that is the activedocument (set mDoc = activedocument).; then after you bring in the slide, use mDoc.Activate

  7. #7
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: SetFocus back to Word (2002)

    Hi Gerry, thanks for the advice, but it doesnt work im afraid. Hans workaround is still the best method i have for this one!
    Thanks,

    pmatz

Posting Permissions

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