Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

change active window

0 views
Skip to first unread message

theintern

unread,
Sep 4, 2008, 6:36:00 PM9/4/08
to
I have some vba that runs some queries in Access, opens up microsoft project,
does some stuff in project, and then opens up Powerpoint and does some stuff
there too. this is all possible because i've included the references, so i
can build this into just one module. the problem however is that my PP code
using the ActiveWindow.Presentation.Slides(1) command and at that time PP
isn't the active window. How do i specifically set the active window to be
PowerPoint?

thanks
Scott

Steve Rindsberg

unread,
Sep 4, 2008, 8:44:21 PM9/4/08
to
In article <C8B1257F-6C44-485C...@microsoft.com>, Theintern
wrote:

Hard to say w/o seeing actual code or knowing what you're trying to do with the
active window (or whether you even need a reference to it).

If you're trying to do something to the first slide, you might be able to drill
down from a reference to the PowerPoint app to .ActivePresentation.Slides(1)

-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Live and in personable in the Help Center at PowerPoint Live
Sept 21-24, San Diego CA, USA
www.pptlive.com

theintern

unread,
Sep 5, 2008, 8:34:00 AM9/5/08
to
here is the code with everything i've tried commented out.

Public Function TriFilter2()

Dim Continue As Integer
Dim pr As MSProject.Application
Dim pp As Object
Dim ppwindow As PowerPoint.DocumentWindow
Dim oPres As PowerPoint.Presentation
Dim waitTime As Integer
Dim waitTime2 As Integer

'Puts it in an infinite loop
Continue = 1
'Runs appropriate queries (which create tables), then opens Project
'and PowerPoint
While Continue = 1
DoCmd.SetWarnings False
DoCmd.OpenQuery "SMquery", acViewNormal, acEdit
DoCmd.OpenQuery "SMdelete", acViewNormal, acEdit
DoCmd.OpenQuery "PIPquery", acViewNormal, acEdit
DoCmd.OpenQuery "PIPdelete", acViewNormal, acEdit
DoCmd.OpenQuery "PLBquery", acViewNormal, acEdit
DoCmd.OpenQuery "PLBdelete", acViewNormal, acEdit
Set pr = New MSProject.Application
'pr.Visible = True
pr.FileOpen ("U:\Estimating Log\Est Schedule\Take-offbackup.mpp")
ImportAll
Set pp = CreateObject("powerpoint.application")
pp.Visible = True
pp.Presentations.Open FileName:="C:\Documents and
Settings\deckers\Desktop\ScheduleOutputbackup.pptm"
'Set oPres = PptApp.Presentations.Open("C:\Documents and
Settings\deckers\Desktop\ScheduleOutputbackup.pptm")
'pp.Active = True
'Set ppwindow = pp.Presentation.Window
'Set ActiveWindow.Caption = "ScheduleOutputbackup.pptm"
'Set ActiveWindow = pp.Presentation.Window
'pp.Activate
'Presentations.Activate
'ActiveWindow = Powerpoint.ActivePresentation.Windows(1)
CreateShow
DoCmd.SetWarnings True
Wend

End Function

theintern

unread,
Sep 5, 2008, 9:30:00 AM9/5/08
to
Also, within the CreateShow sub is where the problem is. see below:

Sub CreateShow()
'Declare the variables
Dim oSlide As Slide
Dim oPicture1 As Shape
Dim oPicture2 As Shape
Dim oPicture3 As Shape
Dim oPicture4 As Shape
Dim oPicture5 As Shape
Dim oPicture6 As Shape
'Dim oPres As PowerPoint.Presentation
'Powerpoint.Application.Activate
'Set oPres = PowerPoint.Presentations(1)
'oPres.Application.Activate

DisplayAlerts = False
ScreenUpdating = False


'**********
'PICTURE 2
'**********
' Change slide index position to the first slide
'HAS PROBLEM WITH THE FOLLOWING LINE OF CODE; THE ACTIVE WINDOW IS 'NOT
POWERPOINT
ActiveWindow.View.GotoSlide 2

' Set oSlide to the first slide in the presentation.
Set oSlide = ActiveWindow.Presentation.Slides(2)

' Set oPicture to the picture file on your computer. Set Link To
' File to false, Save With Document to true, and place it in the
' upper left-hand corner of the slide, sized to 1 by 1 points.
Set oPicture2 = oSlide.Shapes.AddPicture("U:\Estimating Log\Est
Schedule\Directory\TOT\ALLTwoWeeks.gif", _
msoFalse, msoTrue, 1, 1, 1, 1)
' Now scale the picture to full size, with "Relative to original
' picture size" set to true for both height and width.
oPicture2.ScaleHeight 1, msoTrue
oPicture2.ScaleWidth 1, msoTrue

'MORE CODE AFTER THAT, BUT NEVER MAKES IT ANY FARTHER

End Sub

' Move the picture to the center of the slide. Select it.
With ActivePresentation.PageSetup
oPicture2.Select
End With
'Sizes the photo to span the entire width
With ActiveWindow.Selection.ShapeRange(1)
oPicture2.LockAspectRatio = msoFalse
oPicture2.Left = 0
oPicture2.Top = 0
oPicture2.Width = 720
End With

Steve Rindsberg

unread,
Sep 5, 2008, 10:38:07 AM9/5/08
to
In article <49B6F908-6A37-46E5...@microsoft.com>, Theintern wrote:
> here is the code with everything i've tried commented out.

OK, that's a start. What're you trying to do with the window though?
CreateShow is a function/sub you're calling?


Set pp = CreateObject("powerpoint.application")
pp.Visible = True

' change pptapp to pp, make sure this all
' goes on one line
Set oPres = pp.Presentations.Open("C:\Documents and

Settings\deckers\Desktop\ScheduleOutputbackup.pptm")

With oPres.SlideShowSettings
' settings here as desired
'.ShowType = ppShowTypeSpeaker
'.LoopUntilStopped = msoFalse
'.ShowWithNarration = msoTrue
'.ShowWithAnimation = msoTrue
'.RangeType = ppShowAll
'.AdvanceMode = ppSlideShowUseSlideTimings
'.PointerColor.RGB = RGB(Red:=255, Green:=0, Blue:=0)
.Run
End With

That should start the slide show (activating it in the process) but if you need to
activate the window again, this should do it:

oPres.SlideShowWindow.Activate

theintern

unread,
Sep 5, 2008, 11:40:03 AM9/5/08
to
so...Set oPres = pp.Presentations.Open("C:\Documents and
Settings\deckers\Desktop\ScheduleOutputbackup.pptm") worked, but i had
trouble passing it to CreateShow. yes, create show is another sub below this
one that does some stuff in powerpoint (including starting the show). which
is why i need the window active, or another solution to insert pictures, i.e.
Set oSlide = ActiveWindow.Presentation.Slides(1)
Set oPicture1 = oSlide.Shapes.AddPicture("U:\Estimating Log\Est
Schedule\Directory\TOT\ALLThreeWeeks.gif", _

msoFalse, msoTrue, 1, 1, 1, 1)

if i could pass oPres to CreateShow, then i think i could use
oPres.slides(1), but right now it's not letting me do that.

right now i can't use
oPres.SlideShowWindow.Activate
because either there is no slideshowwindow in the main sub, or in the
CreateShow sub it doesn't know what oPres is because i'm having trouble
passing it.

thanks!
scott

Steve Rindsberg

unread,
Sep 5, 2008, 1:30:37 PM9/5/08
to
In article <96771E01-E3BF-40B9...@microsoft.com>, Theintern wrote:
> so...Set oPres = pp.Presentations.Open("C:\Documents and
> Settings\deckers\Desktop\ScheduleOutputbackup.pptm") worked, but i had
> trouble passing it to CreateShow. yes, create show is another sub below this
> one that does some stuff in powerpoint (including starting the show). which
> is why i need the window active, or another solution to insert pictures, i.e.
> Set oSlide = ActiveWindow.Presentation.Slides(1)
> Set oPicture1 = oSlide.Shapes.AddPicture("U:\Estimating Log\Est
> Schedule\Directory\TOT\ALLThreeWeeks.gif", _
> msoFalse, msoTrue, 1, 1, 1, 1)
>
> if i could pass oPres to CreateShow, then i think i could use
> oPres.slides(1), but right now it's not letting me do that.

As it's written, no.

But change this:
Sub CreateShow()

to this:
Sub CreateShow(oPres as Presentation)
or
Sub CreateShow(oPres as Object)

and you should be good.

Call it using:

Call CreateShow(oPres)

from your main routine

'Declare the variables
Dim oSlide As Slide
Dim oPicture1 As Shape
Dim oPicture2 As Shape
Dim oPicture3 As Shape
Dim oPicture4 As Shape
Dim oPicture5 As Shape
Dim oPicture6 As Shape
'Dim oPres As PowerPoint.Presentation
'Powerpoint.Application.Activate
'Set oPres = PowerPoint.Presentations(1)
'oPres.Application.Activate

DisplayAlerts = False
ScreenUpdating = False

>

theintern

unread,
Sep 8, 2008, 9:25:00 AM9/8/08
to
thanks steve. that works great. i thought i tried this already, but i must
have been screwing something up. thanks for the help.

theintern

unread,
Sep 8, 2008, 9:40:01 AM9/8/08
to
actually, i take that back. it doesn't work. false alarm. it's still
giving me the error "Object doens't support this property or method." is
there some reference check box i need to have checked? i think i have all
the PowerPoint references checked, and ActiveX 2.0. any ideas?

thanks

Steve Rindsberg

unread,
Sep 12, 2008, 12:28:34 AM9/12/08
to
Did you also make the change so you're using CALL CreateShow (xxx)?
0 new messages