Consulting

Results 1 to 4 of 4

Thread: VBA - Way to recreate chart from excel in powerpoint (not paste or embed)

  1. #1
    VBAX Newbie
    Joined
    May 2024
    Posts
    2
    Location

    VBA - Way to recreate chart from excel in powerpoint (not paste or embed)

    Basically, I should be able select the chart in excel, run the macro, the macro will open a new instance of PowerPoint, insert a new chart (with the same chart type as the one in excel) and update the ppt chart backend data with the data from the excel chart
    Hope this was clear. Any support would be appreciated!
    All content I found online only suggests code for copy-pasting with (a) link to excel or (b) an embedded chart
    (a) doesn't work because user should be able to edit chart
    (b) doesn't work because user should not have access to full excel file and will also increase size of ppt
    Apologies if I have missed an existing solution here.
    Adding my sample code that can paste as well as embed...
    Sub ExportSelectedChart()
        Dim pptApp As PowerPoint.Application
        Dim pptPres As PowerPoint.Presentation
        Dim pptSlide As PowerPoint.Slide
        Dim Chrt As ChartObject
        'Set Chrt = ThisWorkbook.Sheets("Sheet1").ChartObjects(1)
        If TypeName(Selection) = "ChartArea" Then
            Set pptApp = New PowerPoint.Application
            pptApp.Visible = True
            Set pptPres = pptApp.Presentations.Add
            Set pptSlide = pptPres.Slides.Add(1, ppLayoutBlank)
            Set Chrt = Selection.Parent.Parent
            Chrt.Copy
            'Pastes Chart - But linked to source excel
            'PPTSlide.Shapes.Paste
            'Pastes Embedded Chart - But includes full excel file and size
            pptApp.CommandBars.ExecuteMso ("PasteExcelChartSourceFormatting")
        Else
            MsgBox "Please select a chart in Excel before running this macro.", vbExclamation
        End If
    End Sub

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,107
    Location
    Welcome to VBAX rheseus. Have you looked at the following concept? https://support.microsoft.com/en-au/...d%20click%20OK.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    VBAX Newbie
    Joined
    May 2024
    Posts
    2
    Location
    Thanks for sharing the link. It still doesn't solve my problem though, the options listed are pasting with link, without or embedding, neither of which work for my situation.

    My solution would be closest to the embed option but only the chart data is embedded, not the rest of the excel

  4. #4
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,107
    Location
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Tags for this Thread

Posting Permissions

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