ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Old VBA code in MS office 2007? (https://www.excelbanter.com/excel-programming/391469-old-vba-code-ms-office-2007-a.html)

Yurble

Old VBA code in MS office 2007?
 
Hi all,

I have run this code (the following) in Excel 2003, it works well. Its
to copy all chart in selected WorkSheet to active powerpoint.

But when put this code to Excel 2007, it does not work anymore. Can
anyone help me to modify it to be compatible with Excel 2007. I really
sorry to ask such question, but as you know, I dont know any about
programming, just copy,paste, and do some small modifying.

Really need your help.

Thank in advance


Sub ChartsAndTitlesToPresentation()
' Set a VBE reference to Microsoft PowerPoint Object Library

Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Dim PresentationFileName As Variant
Dim SlideCount As Long
Dim iCht As Integer
Dim sTitle As String
Dim wks As Worksheet

' Reference existing instance of PowerPoint
Set PPApp = GetObject(, "Powerpoint.Application")
' Reference active presentation
Set PPPres = PPApp.ActivePresentation
PPApp.ActiveWindow.ViewType = ppViewSlide

For Each wks In ActiveWorkbook.Windows(1).SelectedSheets
' change ActiveSheet to wks
For iCht = 1 To wks.ChartObjects.Count
With wks.ChartObjects(iCht).Chart

' get chart title
If .HasTitle Then
sTitle = .ChartTitle.Text
Else
sTitle = ""
End If
' copy chart as a picture
.ChartArea.Copy
End With

' Add a new slide and paste in the chart
SlideCount = PPPres.Slides.Count
Set PPSlide = PPPres.Slides.Add(SlideCount + 1, ppLayoutTitleOnly)
PPApp.ActiveWindow.View.GotoSlide PPSlide.SlideIndex
With PPSlide
' paste and select the chart picture
.Shapes.PasteSpecial(Link:=True).Select
' align the chart
PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignLefts,
True
PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignBottoms,
True
PPApp.ActiveWindow.Selection.ShapeRange.IncrementT op -25#
.Shapes.Placeholders(1).TextFrame.TextRange.Text = sTitle
End With

Next
Next

' Clean up
Set PPSlide = Nothing
Set PPPres = Nothing
Set PPApp = Nothing

End Sub


Yurble

Old VBA code in MS office 2007?
 
After testing found that:

Set PPSlide = PPPres.Slides.Add(SlideCount + 1, ppLayoutTitleOnly)
<-- this instruction can not be implement by Powerpoint 2007

..Shapes.PasteSpecial(Link:=True).Select <-- this cause bugs

Is there anyway to update these code to compatible with office 2007??



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com