gigantedemierda
New Member
- Joined
- Apr 4, 2015
- Messages
- 2
Hi, I am new to VBA and I´m trying to fill existing powerpoint presentations with graphs and charts from a workbook.
The workbook has several sheets, which were created in both english and spanish office (I am using Office 2013, but the file may be from an older one). So, sheets have their name, but some appear as "Hoja X" and some as "Sheet Y". Just 1 and 3 are repeated (i.e. Hoja 1, Hoja 3, Sheet 1 and Sheet 3 appear in the workbook.)
(Here's a pic, to make things clearer.)
The power point has several slides, and sometimes I need to put more than one graph per slide. Thus, I need to resize and position the stuff I'm copying into the ppt.
This is what I have for just one slide:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">Sub ChartToPresentation()
' Set a VBE reference to Microsoft PowerPoint Object Library
Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
' Reference existing instance of PowerPoint
Set PPApp = GetObject(,"Powerpoint.Application")
' Reference active presentation
Set PPPres = PPApp.ActivePresentation
PPApp.ActiveWindow.ViewType = ppViewSlide
' 6 - Convocatoria - Presentismo
Set PPSlide = PPPres.Slides(6)
ThisWorkbook.Worksheets("FyV").ChartObjects(15).Select
'Hoja8.ChartObjects(15).Select
ActiveChart.CopyPicture Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture
PPSlide.Shapes.Paste
PPApp.ActiveWindow.Selection.ShapeRange.Left =10
PPApp.ActiveWindow.Selection.ShapeRange.Top =20
'PPSlide.ShapeRange.Width = 80
'PPSlide.ShapeRange.Height = 80
</code>EndSub
However, I´m having several problems due to the fact that I´m selecting stuff.
So, I am looking for a way to call graphs by the name of the worksheet and graph name which allows me to resize them.
Thanks in advance,
Bauti
The workbook has several sheets, which were created in both english and spanish office (I am using Office 2013, but the file may be from an older one). So, sheets have their name, but some appear as "Hoja X" and some as "Sheet Y". Just 1 and 3 are repeated (i.e. Hoja 1, Hoja 3, Sheet 1 and Sheet 3 appear in the workbook.)
(Here's a pic, to make things clearer.)
The power point has several slides, and sometimes I need to put more than one graph per slide. Thus, I need to resize and position the stuff I'm copying into the ppt.
This is what I have for just one slide:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">Sub ChartToPresentation()
' Set a VBE reference to Microsoft PowerPoint Object Library
Dim PPApp As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
' Reference existing instance of PowerPoint
Set PPApp = GetObject(,"Powerpoint.Application")
' Reference active presentation
Set PPPres = PPApp.ActivePresentation
PPApp.ActiveWindow.ViewType = ppViewSlide
' 6 - Convocatoria - Presentismo
Set PPSlide = PPPres.Slides(6)
ThisWorkbook.Worksheets("FyV").ChartObjects(15).Select
'Hoja8.ChartObjects(15).Select
ActiveChart.CopyPicture Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture
PPSlide.Shapes.Paste
PPApp.ActiveWindow.Selection.ShapeRange.Left =10
PPApp.ActiveWindow.Selection.ShapeRange.Top =20
'PPSlide.ShapeRange.Width = 80
'PPSlide.ShapeRange.Height = 80
</code>EndSub
However, I´m having several problems due to the fact that I´m selecting stuff.
- When I ask for
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;"> ThisWorkbook.Worksheets("FyV").ChartObjects(15).Select</code>I get chart 24 from that worksheet. When I ask for charts 3, 12 and 13 I get chart 5.- When I uncomment
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">'PPSlide.ShapeRange.Width = 80
'PPSlide.ShapeRange.Height = 80</code>
Compile error: Method or data member not found
- Sometimes the line:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">ThisWorkbook.Worksheets("FyV").ChartObjects(XX).Select</code>
Run-time error '1004': Application-defined or object-defined errorBut XX exists, and it is on "FyV"
- When I uncomment
So, I am looking for a way to call graphs by the name of the worksheet and graph name which allows me to resize them.
Thanks in advance,
Bauti