You are here:

Excel/Code to launch PowerPoint in portrait orientation

Advertisement


Question
Hi Tom,

Some time ago, you helped me (enormously!) with some code to capture a range of cells in a spreadsheet as a picture, then launch PowerPoint and paste that image on a blank slide. I have used this quite a few times for a variety of projects. :)

I would like to add another feature to open PowerPoint in portrait orientation (vs landscape, which is the default) and despite Googling it every which way possible, I am unable to get the code to work properly.

I think I know WHERE to insert the code, but I am missing the proper syntax.

Thank you!

Barbara



Below is the code you provided:

Sub CreateRegionOnSlide()
 
 Dim ppApp As PowerPoint.Application
 Dim ppPres As PowerPoint.Presentation
 Dim ppShape As PowerPoint.Shape
 Dim ppCurrentSlide As PowerPoint.Slide
 Dim r As Range, sh As Worksheet

 Set r = ActiveSheet.Range("b2:i22")

 Worksheets.Add After:=Worksheets(Worksheets.Count)
 Set sh = Worksheets(Worksheets.Count)
 r.Parent.Activate
 r.Select
 Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture
 sh.Pictures.Paste
 sh.Shapes(1).Copy
 
 Set ppApp = CreateObject("PowerPoint.Application")
 ppApp.Visible = True
  
 Set ppPres = ppApp.Presentations.Add(msoTrue)
 Set ppCurrentSlide = ppPres.Slides.Add(Index:=1, Layout:=ppLayoutBlank)
   
 With ppCurrentSlide
   ppCurrentSlide.Shapes.Paste
   Set ppShp = ppCurrentSlide.Shapes(1)
   ppShp.Top = 30
   ppShp.Left = 3
   ppShp.Width = 400
         
 End With
  
End Sub

Answer
Barbara,

this worked for me:

Sub CreateRegionOnSlide()
 
 Dim ppApp As PowerPoint.Application
 Dim ppPres As PowerPoint.Presentation
 Dim ppShape As PowerPoint.Shape
 Dim ppCurrentSlide As PowerPoint.Slide
 Dim r As Range, sh As Worksheet

 Set r = ActiveSheet.Range("b2:i22")

 Worksheets.Add After:=Worksheets(Worksheets.Count)
 Set sh = Worksheets(Worksheets.Count)
 r.Parent.Activate
 r.Select
 Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture
 sh.Pictures.Paste
 sh.Shapes(1).Copy
 
 Set ppApp = CreateObject("PowerPoint.Application")
 ppApp.Visible = True
  
 Set ppPres = ppApp.Presentations.Add(msoTrue)

 ppPres.PageSetup.SlideOrientation = msoOrientationVertical  '<== added
' if you use late binding (and this code doesn't) the constant value
' for msoOrientationVertical is 2

 Set ppCurrentSlide = ppPres.Slides.Add(Index:=1, Layout:=ppLayoutBlank)
   
 With ppCurrentSlide
   ppCurrentSlide.Shapes.Paste
   Set ppShp = ppCurrentSlide.Shapes(1)
   ppShp.Top = 30
   ppShp.Left = 3
   ppShp.Width = 400
         
 End With
  
End Sub

--
Regards,
Tom Ogilvy

About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Tom Ogilvy

Expertise

Selected as an Excel MVP by Microsoft since 1999. Answering Excel questions in Allexperts since its inception in 2001. Able to answer questions on almost all aspects of Excel's internal capabilities. If seeking a VBA solution, please specify that in your question itself so I give you the answer you want. [Excel has weak protection - if you are distributing an application, I don't answer questions on how to protect your project from your users.]

Experience

Extensive experience.

Education/Credentials
Master of Science (MS) degree Operations Research (ORSA)

Awards and Honors
Microsoft MVP in Excel.

©2016 About.com. All rights reserved.