Consulting

Results 1 to 4 of 4

Thread: Importing an Excel range with source formatting

  1. #1
    VBAX Newbie
    Joined
    Feb 2017
    Posts
    4
    Location

    Importing an Excel range with source formatting

    From PowerPoint I want to open an Excel spreadsheet and copy a range into a slide. I can do this as a picture, but my user wants to edit the imported data on the PowerPoint slide. Manually, she copies the range and uses the Paste option 'Keep Source Formatting (K)' in order to do this. I can't see how to do this in PowerPoint VBA.

    Below is the section of code I use for copy and pasting.

    ActivePresentation.Slides(21).Select

    'Open worksheet and adjust the column widths
    Set xlsheet = xlwkb.Worksheets("Customer Stats")

    'Get section to copy
    Set xlrange = xlsheet.Range(xlsheet.Cells(2, 2), xlsheet.Cells(16, 3))
    xlrange.WrapText = True: xlrange.Font.Name = "Arial": xlrange.Font.Size = 10

    'Insert section and place
    Set sldSlide = ActivePresentation.Slides(21)
    xlrange.CopyPicture Appearance:=xlScreen, Format:=xlPicture
    sldSlide.Shapes.PasteSpecial

    Application.ActiveWindow.Selection.ShapeRange.Left = 300
    Application.ActiveWindow.Selection.ShapeRange.Top = 80
    Application.ActiveWindow.Selection.ShapeRange.ScaleHeight 0.8, msoTrue
    Application.ActiveWindow.Selection.ShapeRange.ScaleWidth 0.8, msoTrue

    Any help would be appreciated.

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    You don#'t say which version.

    In later versions you could try

    CommandBars.ExecuteMso ("PasteExcelChartSourceFormatting")
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Newbie
    Joined
    Feb 2017
    Posts
    4
    Location
    Thanks John. I'd tried CommandBars.ExecuteMso ("PasteExcelChartSourceFormatting") but got an Automation Error.
    Eventually, I found that the problem was in the Copy.
    Instead of:
    xlrange.CopyPicture Appearance:=xlScreen, Format:=xlPicture
    I should have used:
    xlrange.Copy
    Application.CommandBars.ExecuteMso ("PasteSourceFormatting")
    This then it copies the range across from Excel and it is editable.

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    I don't know why I thought you were pasting a chart!
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

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