VBA Programming in Excel with Powerpoint

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to copy 10X4 cells from excel and paste it in powerpoint slide.
It opens the pp, add a new slide (pplayoutTitleOnly) and pastes it there.
Now I need to position the table and change font, size etc.
if I record the macro this is what I get.
ActiveWindow.Selection.TextRange.Font.Size = 18
Since excel and pp are open and the code is in excel editor, i think it is
confused with activewindow.
How do I change the font and other format.

any help is appreciated
Thanks
MVM
 
I am trying to copy 10X4 cells from excel and paste it in powerpoint slide.
It opens the pp, add a new slide (pplayoutTitleOnly) and pastes it there.

By "it", I assume you mean your code that's running in Excel?
Now I need to position the table and change font, size etc.
if I record the macro this is what I get.
ActiveWindow.Selection.TextRange.Font.Size = 18

You record that where ... in PowerPoint or Excel?
Since excel and pp are open and the code is in excel editor, i think it is
confused with activewindow.

It's not a matter of either one getting confused; ActiveWindow will always
refer to the active window of the app that your code is running in unless you
set a reference to a different application.
How do I change the font and other format.


Post the portion of your code that selects and copies the info from Excel to
PowerPoint, assuming that's what you're doing, and perhaps someone can help
modify it to do what you want.
 
1> By "it", I assume you mean your code that's running in Excel?
Yes you are right
2> > ActiveWindow.Selection.TextRange.Font.Size = 18
You record that where ... in PowerPoint or Excel?

yes, this is recorded in PowerPoint
3 code
________________________________________
.....
Set objPP = GetObject("", "PowerPoint.Application")
objPP.Visible = True
Set pp = objPP.Presentations.Open("C:\BSC - 4th Qtr Service Awards.ppt")
i = 1
While i < myR.Rows.Count
Set moveR = myR.Range(myR(i, 1), myR(i + 9, 1))
Set moveR = myR.Range(moveR, moveR.End(xlToRight))
With pp.Slides
.Add Index:=.Count + 1, Layout:=ppLayoutTitleOnly
moveR.Copy
pp.Slides(.Count).Shapes.Paste
pp.Slides(.Count).Shapes(pp.Slides(.Count).Shapes.Count).Name = "myTable"
With pp.Slides(.Count).Shapes("myTable")
.Top = 125
.Left = 50
End With
objPP.ActiveWindow.ViewType = ppViewNormal

' ActiveWindow.Selection.TextRange.Font.Name = "Times New Roman"
With objPP.ActiveWindow.Selection.TextRange.Font
.Size = 16
.Bold = msoTrue
.Name = "Times New Roman"
End With
.....

This changes the font of title on first slide, not on the just added one.

Thanks
MVM
 
See comments inserted into code ...
________________________________________
.....
Set objPP = GetObject("", "PowerPoint.Application")
objPP.Visible = True
Set pp = objPP.Presentations.Open("C:\BSC - 4th Qtr Service Awards.ppt")
i = 1
While i < myR.Rows.Count
Set moveR = myR.Range(myR(i, 1), myR(i + 9, 1))
Set moveR = myR.Range(moveR, moveR.End(xlToRight))
With pp.Slides
.Add Index:=.Count + 1, Layout:=ppLayoutTitleOnly
moveR.Copy
pp.Slides(.Count).Shapes.Paste
pp.Slides(.Count).Shapes(pp.Slides(.Count).Shapes.Count).Name = "myTable"
With pp.Slides(.Count).Shapes("myTable")
.Top = 125
.Left = 50
End With
objPP.ActiveWindow.ViewType = ppViewNormal

Here's the problem: at this point in your code, you've added a table to a new
slide and set PPT to show the slide but the table isn't selected, trying to change
its font won't work.
' ActiveWindow.Selection.TextRange.Font.Name = "Times New Roman"
With objPP.ActiveWindow.Selection.TextRange.Font

But since you have a reference to PowerPoint and know the index of the new slide
and the name of the table shape, use that instead:

With pp.Slides(.Count).Shapes("myTable")
 
Also
With pp.Slides
.Add Index:=.Count + 1, Layout:=ppLayoutTitleOnly
moveR.Copy
will not copy the range since you are issuing the command to PPT. get
the moveR.copy out of the With pp.slides statement

Brian Reilly, MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top