ActivePresentation.Slides(X).S­elect

S

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.

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
 
S

smonczka

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
 
S

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...

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
 
S

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.

Have a good one,
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top