PPT.InteractWithChartLocation in MS PowerPoint 2010 to Change Chart Locations in VB.NET

In this article I am going to explain about how to Change Chart Locations in a Microsoft PowerPoint 2010 presentation.
  • 2524

Introduction

In this article I am going to explain about how to Change Chart Locations in a Microsoft PowerPoint 2010 presentation. For this we use PPT.InteractWithChartLocation Microsoft PowerPoint 2010. In this application you need to insert a chart in first slide then use this code in VBA.

Microsoft Office 2010 offer some powerful tools, using this tools you can create application. Using Microsoft Visual Basic for Applications (VBA) you can create your own application according to your need. These application can performer some specific task.

For creating application we can use

  • VBA host of Excel 2010
  • VBA host of PowerPoint 2010
  • VBA host of Word 2010

NOTE : OneNote 2010 is not a VBA host.

Code that we use in this application are given below

Sub InteractWithChartLocation()

    ' Use this procedure to demonstrate
    
' working with the location of a chart. 

    Dim vip As Shape
    Dim a As Chart 

    ' If there isn't already a second slide, create one now:

    If ActivePresentation.Slides.Count < 2 Then
        ActivePresentation.Slides.Add(2, ppLayoutBlank)
    End 
If 

    ' Loop through all the shapes on the first slide,
    
' looking for the first chart shape:

    For Each vip In ActivePresentation.Slides(1).Shapes
        If vip.Type = msoChart 
Then
            Exit For
        End If
    Next vip 

    ' If you found a chart, keep going:

    If vip.Type = msoChart Then

        ' Cut the shape to the clipboard:
        vip.Cut() 

        Dim b As ShapeRange
        Dim ns As Shape 

        ' Paste the shape from the clipboard onto the second slide.
        
' This method returns a ShapeRange--you need a
        ' reference to the first pasted shape:

        b = ActivePresentation.Slides(2).Shapes.Paste
        ns = b.Item(1) 

        ' Set the location of the new shape:

        ns.Top = 10
        ns.Left = 10

    End If
End Sub

Step for creating Application

Step 1 : Start Microsoft PowerPoint 2010 :

1 (1).jpg

Step 2 : Insert a chart in first slide : To insert chart in slide click on insert==>now click on chart ==> select chart and click on ok

Clipboard15.jpg
 

Step 3 : Using Alt + F11 Key Start Visual Basic for Applications (VBA) Window :

2.jpg
 

Step 4 : Select on VBAProject(Presentation 1) : 
  

  3 (1).jpg

Step 5 : Right Click On VBAProject(Presentation 1) ==> Goto Insert==> Goto Module & click on Module:

4.jpg
 

Step 6 : Write Code in Visual Basic for Applications (VBA) Window :

5.jpg
 

Step 7 : Run Application using F5 :

Step 8 : Macros window will open, Select Macros name and click on Run Button :

6.jpg
 

Step 9 : Output of Application :
Location of chart before run the application

8.jpg
 

Location of chart ofter run the application

9.jpg

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.