Discussion:
ActivePresentation.Slides(X).S­elect
(too old to reply)
smonczka
2005-08-07 19:23:58 UTC
Permalink
I need some help with selecting a slide from VBA. I tried using
ActivePresentation.Slides(X).S­elect where X is the number of the
slide but still run into the error "Invalid request. Nothing
appropriate is currently selected."

The code I have is selecting the first slide in the presentation ande
inporting an excel object and then needs to select the next slide and
do the same. It does this three times, but errors out after the first
slide.

ActivePresentation.Slides(1).Select
With ActiveWindow.Selection.ShapeRange
.Fill.Transparency = 0#
.LockAspectRatio = msoFalse
End With
ActivePresentation.Slides(2).Select
With ActiveWindow.Selection.ShapeRange
.Fill.Transparency = 0#
.LockAspectRatio = msoFalse

Thanks a lot for your help.
Steve
Steve Rindsberg
2005-08-07 20:50:30 UTC
Permalink
Post by smonczka
I need some help with selecting a slide from VBA. I tried using
ActivePresentation.Slides(X).S­elect where X is the number of the
slide but still run into the error "Invalid request. Nothing
appropriate is currently selected."
The code I have is selecting the first slide in the presentation ande
inporting an excel object and then needs to select the next slide and
do the same. It does this three times, but errors out after the first
slide.
For starters, you don't need to select the slide, you just need a reference to
it in order to work with the slide's shapes.

Dim X as Long
Dim oSh as Shape
For X = 1 to 3 ' or whatever range of slides you want
With ActivePresentation.Slides(X)
' Do what you want with the slide here
' It's not clear from your example code what you want to do

' For example, if you already have the Excel data on the clipboard,
' you could do
.Shapes.Paste
' to paste it onto the slide

' or
set oSh = .Shapes.AddOLEObject(Filename:="Myfile.XLS")
With oSh
.Top = 0 ' or whatever
.Left = 0
' set other properties as needed
End With
End with
Next ' X, or slide
Post by smonczka
ActivePresentation.Slides(1).Select
With ActiveWindow.Selection.ShapeRange
.Fill.Transparency = 0#
.LockAspectRatio = msoFalse
End With
ActivePresentation.Slides(2).Select
With ActiveWindow.Selection.ShapeRange
.Fill.Transparency = 0#
.LockAspectRatio = msoFalse
Thanks a lot for your help.
Steve
-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
smonczka
2005-08-09 18:43:39 UTC
Permalink
Steve, please pardon me but most of my experience with VBA is recording
macros in Excel then tweaking them to do what I want. What I am
trying to do here is copy three excel files (one sheet from each) to
three separate Powerpoint slides in the same presentation. Then resize
the imported sheets to be the full size of the slide.

When I first tried this by creating a macro and having it mimic my
original steps. But when I ran the macro it took all of my files and
put it into the same slide.

I tried using ActivePresentation.Slides(1).S¬elect, assuming it was
similar to the sheet select statement used in Excel, but my code
errored out when I used that.

I tried using the code you suggested but again errored out on With
ActivePresentation.Slides(1) saying that nothing had been selected.

Could you explain to me how this is supposed to work or even a
reference to where I could look up the code would be helpful.

Thank you for both your time and effort.

Steve
Steve Rindsberg
2005-08-10 00:43:36 UTC
Permalink
Post by smonczka
When I first tried this by creating a macro and having it mimic my
original steps. But when I ran the macro it took all of my files and
put it into the same slide.
I tried using ActivePresentation.Slides(1).S¬elect, assuming it was
similar to the sheet select statement used in Excel, but my code
errored out when I used that.
I tried using the code you suggested but again errored out on With
ActivePresentation.Slides(1) saying that nothing had been selected.
I'd expect an error, though not that one, if there weren't three slides already in the
presentation. This works here, assuming there are files in C:\temp called excel1.xls, excel2.xls
and so on

Sub InsertExcelSheets()

Dim X As Long
Dim oSh As Shape
Dim sFilename As String

For X = 1 To 3 ' or whatever range of slides you want
With ActivePresentation.Slides(X)
' This assumes files named excel1.xls, excel2.xls etc
sFilename = "c:\temp\excel" & CStr(X) & ".xls"
Set oSh = .Shapes.AddOLEObject(FileName:=sFilename)
With oSh
' Reset to full slide size
.LockAspectRatio = True ' by default
' set it false to let the shape get distorted
.Top = 0 ' or whatever
.Left = 0
.Height = ActivePresentation.PageSetup.SlideHeight
.Width = ActivePresentation.PageSetup.SlideWidth
' set other properties as needed
End With

End With
Post by smonczka
Could you explain to me how this is supposed to work or even a
reference to where I could look up the code would be helpful.
Which bits do and don't you understand? No point in my writing a half-hour tutorial to explain
stuff you already have under the belt.

-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
smonczka
2005-08-10 01:50:30 UTC
Permalink
Actually Steve it's the first line that is throwing me. I have three
slides in the presentation named 1, 2 and 3. The three excel files are
located in the C:\Temp directory. So the code should look like this...

Dim X As Long
Dim oSh As Shape
Dim sFilename As String
With ActivePresentation.Slides(1)
sFilename = "c:\temp\excel" & CStr(1) & ".xls"
Set oSh = .Shapes.AddOLEObject(FileName:¬=sFilename)
With oSh
.LockAspectRatio = False
.Top = 0
.Left = 0
.Height = ActivePresentation.PageSetup.S¬lideHeight
.Width = ActivePresentation.PageSetup.S¬lideWidth
End With
End With

This pulls in the first excel file and copies the first sheet to slide
one. Sets the Aspect Ratio to False, places the file in the top left
corner and then sets the width and height of the excel file that was
imported to the max for the slide. But when I run the code I get the
following error... "Invalid outside procedure" on the first line
With ActivePresentation.Slides(1). So I must be doing something wrong.
Only I have no idea what.

Also the line sFilename = "c:\temp\excel" & CStr(1) & ".xls" does this
line tell the code to import a file in C:\Temp called excel & 1 & .xls?
If so why not just say sFilename = "c:\temp\excel1.xls"?

Thanks again for all your help,
Steve
Steve Rindsberg
2005-08-10 04:36:26 UTC
Permalink
Post by smonczka
Actually Steve it's the first line that is throwing me. I have three
slides in the presentation named 1, 2 and 3. The three excel files are
located in the C:\Temp directory. So the code should look like this...
Nope.

It needs

Sub Something()

at the beginning and

End Sub

at the end. I think you left that out of the code I posted when you
copy/pasted.
Post by smonczka
Dim X As Long
Dim oSh As Shape
Dim sFilename As String
With ActivePresentation.Slides(1)
sFilename = "c:\temp\excel" & CStr(1) & ".xls"
Set oSh = .Shapes.AddOLEObject(FileName:¬=sFilename)
With oSh
.LockAspectRatio = False
.Top = 0
.Left = 0
.Height = ActivePresentation.PageSetup.S¬lideHeight
.Width = ActivePresentation.PageSetup.S¬lideWidth
End With
End With
This pulls in the first excel file and copies the first sheet to slide
one. Sets the Aspect Ratio to False, places the file in the top left
corner and then sets the width and height of the excel file that was
imported to the max for the slide. But when I run the code I get the
following error... "Invalid outside procedure" on the first line
With ActivePresentation.Slides(1). So I must be doing something wrong.
Only I have no idea what.
Also the line sFilename = "c:\temp\excel" & CStr(1) & ".xls" does this
line tell the code to import a file in C:\Temp called excel & 1 & .xls?
If so why not just say sFilename = "c:\temp\excel1.xls"?
Do you want the same XLS file on each slide or a different one on each?
That line is part of a loop; X changes each time through the loop.
The first time through it equals 1 so the macro inserts excel1.xls

Next time through, it's 2 so you get excel2.xls
And so on
Post by smonczka
Thanks again for all your help,
Steve
-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
smonczka
2005-08-10 05:06:23 UTC
Permalink
How does it know to stop the loop?
Steve Rindsberg
2005-08-10 16:35:49 UTC
Permalink
Post by smonczka
How does it know to stop the loop?
For X = 1 to 3

It increments X each time it completes the code in the loop and keeps looping
until X = 3

Sounds like you might want to go shopping for a good basic VB book if you want
to pursue macro coding. It'd be very productive to get the basics (pardon)
under your belt. This newsgroup isn't really the place for VB tutorials,
though we're happy to help in applying VB/VBA to PowerPoint.

-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
smonczka
2005-08-10 21:14:30 UTC
Permalink
Steve Thanks for all your help on this. The code works perfectly.
Learning how to code in VB wasn't my intention when I started this. So
thank you for taking the time to point me in the right direction.

Have a good one,
Steve
Steve Rindsberg
2005-08-11 03:05:04 UTC
Permalink
Post by smonczka
Steve Thanks for all your help on this. The code works perfectly.
Learning how to code in VB wasn't my intention when I started this. So
thank you for taking the time to point me in the right direction.
Excellent. Glad it's working well for you.


-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================

Loading...