View Single Post
  #4   Report Post  
Hari Prasadh
 
Posts: n/a
Default

Hi Steve/Brian,

Oops, sorry if I misled anyone. I got the idea (of controlling PPT from
excel) and great parts of the syntax from Jon and then "meshed" it with
snippets of other NG codes to customise it to my requirements. So bug is in
my meshing (and incorrect understanding of the same) and not with Jon's
code.

do you call the OLE object's Update method before closing the app/releasing
the reference to the object's variable?


Im not sure what you mean by Update method. Please tell me about the same.

I have 2 sets of codes: -

a) First is I receive CSV file having some data. I transpose, sort perform
Statistical tests on it and get it in to a form where it could be readily
pasted in to PPT. This is one macro.

b) Second is taking the formatted range in the CSV file above and calling a
SUB which would paste this Data in to an already existing Excel chart OLE
object within a PPT (having a single slide). (The PPT file may or may not be
open depending on whether am updating data of other objects in the slide or
not).

It is the part b) with which Im having the present problem and am posting
part b) below.

(Latest update : - My colleagues included a line of code below -
ograph.save - (ograph is the name of the excel workbook which is an OLE in
PPT) which they claimed to solve the problem I posted, but I would still
like to double check from you. Steve, when you said "update" do you mean
save the object?)

Option Explicit
Public oPPTApp1 As PowerPoint.Application
Dim oPPTShape1 As PowerPoint.Shape
Dim rngNewRange1 As Excel.Range
Dim oGraph1 As Workbook
Dim Excelwksheet As Worksheet
Dim Excelchartsheet As chart
Dim path As String
Dim PPT As PowerPoint.Presentation
Dim a as Double
Dim b as Double
Dim c as Double
Dim d as Double

Sub UpdateExcelDataChart(filepath As String, objName As String, flag As
Integer, sheetname As String, chartname As String)

Set oPPTApp1 = CreateObject("PowerPoint.Application")

oPPTApp1.Visible = msoTrue

If flag = 0 Then

oPPTApp1.Presentations.Open (filepath)
Else

End If

'There is a single slide in the presentation so can afford to use slides(1)

With oPPTApp1.ActivePresentation.Slides(1)
For Each oPPTShape1 In .Shapes


'objname is the name of the object within PPT whose data needs to be
updated.

If oPPTShape1.Name = objName Then

'a, b, c and d are being used because Excel OLE objects in PPT have a habit
on going for getting dislocated while we are updating them.

a = oPPTShape1.Top

b = oPPTShape1.Left

c = oPPTShape1.Height

D = oPPTShape1.Width


If oPPTShape1.OLEFormat.progID = "Excel.Chart.8" Then

Set oGraph1 = oPPTShape1.OLEFormat.Object

Set Excelwksheet = oGraph1.Worksheets(sheetname)

' Before this sub was called we already have some data in the clipboard
hence pasting below.

Excelwksheet.Range("B1").PasteSpecial xlPasteValues


'Though am just updating the data in a workbook for the chart to get updated
am forced to activate
' the chart below as the view remains in worksheet based on above pasting.

Set Excelchartsheet = oGraph1.Charts(chartname)

Excelchartsheet.Activate

oPPTShape1.LockAspectRatio = msoFalse
oPPTShape1.Top = a
oPPTShape1.Left = b
oPPTShape1.Height = c
oPPTShape1.Width = D

End If
End If


Next oPPTShape1


End With

Application.DisplayAlerts = False

oPPTApp1.ActivePresentation.SaveAs ("D:\Dummy\NRAUTE001.ppt")

oPPTApp1.ActivePresentation.Close

End Sub



Thanks a lot,
Hari
India

"Brian Reilly, MS MVP" wrote in message
...
Hari,
First mistake is using any of Jon P's instructions. (VBG) Jon is a
good friend and a well respected MVP. But that doesn't stop us from
teasing him (g).

As Steve said we aren't sure what you are doing here (exactly by code)
so can you post the relevant parts.

Then we can let Jon Peltier answer his own mess (vbg). Couldn't resist
Jon, Hari is a recent regular in the PPT NG.

Hari, Jon is a regular stop in in the PPT NewsGroup and works
regularly in Excel and PPT integration all the time.

Brian Reilly, MVP

On Tue, 2 Aug 2005 01:18:42 +0530, "Hari Prasadh"
wrote: