Paste Excel Chart as Embedded Object, No Link to Excel File


"Excel VBA Help"

 

Go Back   The Code Cage Forums > Microsoft Topics > Microsoft Excel Forum
Our Info Pages:-
The Code Cage - Microsoft Office help

Notices

Microsoft Excel Forum Members Post questions in this forum if they are related to using Microsoft Excel, this includes Worksheet Functions, Excel VBA Programming, Simple Macro Code & Charting, Excel formula etc.

New Reply
Thread Tools Rate Thread Display Modes
  #1  
Unread 9th November 2012, 15:38
WildRose0706's Avatar
WildRose0706 WildRose0706 is offline
Junior Member
MS Office Version: Ms Office 2010
MS Office Skill Level: Proficient with MS Office
 
Join Date: Nov 2012
Location: Montreal, Quebec
Posts: 1
Posts Per Day: 0.00
My Top Tip Count: 0
Thanks to others: 0
Thanked 0 Times in 0 Posts
Reputation: 10 (0) WildRose0706 is on a distinguished road
Canada
Default Paste Excel Chart as Embedded Object, No Link to Excel File
     Excel: VBA   


Hello,

Here is my goal:

Loop through active Excel workbook
Copy each chart (1 chart per worksheet)

Paste each chart onto a separate slide in PowerPoint

My code works fine, with one exception.

I need the code to paste the chart as embedded, keeping source formatting, with NO link to the original Excel file.

I WOULD, however, like to be able to right-click the chart in PowerPoint and be able to select EDIT DATA to open Excel and edit/view the data. This WITHOUT opening the original source file - just Excel.

Here is my code - much of which is attributed to Jon Pelletier and others:

VBA CODE:
Sub CopyCharts() 
    Dim ppApp As Object 'PowerPoint.Application
    Dim ppSlide As Object 'PowerPoint.Slide
    Dim ppShape As Object 'PowerPoint.Shape
    Dim ppChart As Object 'PowerPoint.Chart
     
    Dim ws As Excel.Worksheet 
    Dim CO As Excel.ChartObject 
     
     'Try access to Powerpoint
    On Error Resume Next 
    Set ppApp = GetObject(, "PowerPoint.Application") 
    On Error Goto 0 
    If ppApp Is Nothing Then 
        MsgBox "Open your presentation first." 
        Exit Sub 
    End If 
     
     'Visit each sheet
    For Each ws In Worksheets 
        For Each CO In ws.ChartObjects 
            With ppApp.ActivePresentation 
                 'Create a new slide, use the first slide as template
                .Slides(1).Copy 
                .Slides.Paste 
                Set ppSlide = .Slides(.Slides.Count) 
                ppSlide.Select 
            End With 
             'Copy the chart to the slide
            CO.Copy 
             
            ppApp.ActiveWindow.ViewType = 1 
             
            ppApp.ActiveWindow.View.Paste 
             
             
             'Access it
            Set ppShape = ppSlide.Shapes(ppSlide.Shapes.Count) 
             'Break the link to Excel
            Set ppChart = ppShape.Chart 
             'ppChart.ChartData.BreakLink
        Next 
    Next 
End Sub 

Hope I pasted my code properly!!

Thanks!

The Code Cage Advertisment
Advertisement
New Reply
The Code Cage at Facebookhe Code Cage at Twitter


Tags
chart, embedded, excel, file, link, object, paste

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

The Code Cage Affilliates



http://www.thecodecage.com/forumz tested by McAfee Security http://www.thecodecage.com/forumz tested by McAfee Security

All times are GMT +1. The time now is 12:53.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Template-Modifications by TMS
No part of this board, functionality or creatives may be copied or reproduced either in part or full without the express permission of The Code Cage Team.
Copyright ©2008 - , Simon lloyd.
We are not associated with nor employed by Microsoft in any way, we simply provide resources!
All MS office icons are registered trademarks of the application they represent and are used with permission from Microsoft
UA-8135493-1
Cultural Forum | Study at Malaysian University