'NOTA: Marcar referencia (Herramienta -> Referencias...)
' "Microsoft PowerPoint 14.0 Object Library"
Sub CeldaDeExcelPP()
Dim LibroExcel As Workbook 'Libro Excel
Dim ppApp As PowerPoint.Application 'Aplicación PP
Dim PresPP As PowerPoint.Presentation 'Presentación PP
Dim DirLibroExcel As String 'Dirección Libro Excel
Dim DirPresPP As String 'Dirección Presentación PP
'Desactivamos las alertas
Application.DisplayAlerts = False
'Indicamos la ubicación del Libro de Excel y Presentación PP
DirLibroExcel = "D:\Pruebas\Libro Excel.xlsx"
DirPresPP = "D:\Pruebas\Presentación PP.pptx"
'Se abre el Powerpoint si no estuviera abierto
If ppApp Is Nothing Then Set ppApp = New PowerPoint.Application
ppApp.Visible = True
'Abrimos el libro de Excel y la presentación PP
Set LibroExcel = Workbooks.Open(DirLibroExcel)
Set PresPP = ppApp.Presentations.Open(DirPresPP)
'Copiamos el valor de la celda de Excel en la lámina de PP seleccionada
PresPP.Slides(1).Shapes(3).TextFrame.TextRange.Text = _
LibroExcel.Sheets("Celda Origen").Cells(2, 2).Value
'Cerramos el Libro Excel sin guardar cambios
LibroExcel.Close False
'Cerramos la Presentació PP guardando los cambios
PresPP.Save
'PresPP.Close
'Liberamos memoria
Set LibroExcel = Nothing
Set PresPP = Nothing
Set ppApp = Nothing
'Activamos nuevamente las alertas
Application.DisplayAlerts = True
End Sub
Ejemplo para pasar una tabla de un libro Excel a una presentación PP:
'NOTA: Marcar referencia (Herramienta -> Referencias...)
' "Microsoft PowerPoint 14.0 Object Library"
Sub TablaDeExcelPP()
Dim LibroExcel As Workbook 'Libro Excel
Dim ppApp As PowerPoint.Application 'Aplicación PP
Dim PresPP As PowerPoint.Presentation 'Presentación PP
Dim DirLibroExcel As String 'Dirección Libro Excel
Dim DirPresPP As String 'Dirección Presentación PP
'Desactivamos las alertas
Application.DisplayAlerts = False
'Indicamos la ubicación del Libro de Excel y Presentación PP
DirLibroExcel = "D:\Pruebas\Libro Excel.xlsx"
DirPresPP = "D:\Pruebas\Presentación PP.pptx"
'Se abre el Powerpoint si no estuviera abierto
If ppApp Is Nothing Then Set ppApp = New PowerPoint.Application
ppApp.Visible = True
'Abrimos el libro de Excel y la presentación PP
Set LibroExcel = Workbooks.Open(DirLibroExcel)
Set PresPP = ppApp.Presentations.Open(DirPresPP)
'Copiamos la tabla del Libro de Excel
LibroExcel.Sheets("Tabla Origen").Range("A1:F19").Copy
'Pegamos la tabla en la presentación PP
'With PresPP.Slides(2).Shapes.PasteSpecial(link:=True) 'Vinculado
With PresPP.Slides(2).Shapes.PasteSpecial(2) 'Imagen
.LockAspectRatio = msoFalse
.Height = 400 'Largo
.Width = 600 'Ancho
.Left = 50 'Posición horizontal
.Top = 80 'Posición vertical
End With
'Cerramos el Libro Excel sin guardar cambios
LibroExcel.Close False
'Cerramos la Presentació PP guardando los cambios
PresPP.Save
'PresPP.Close
'Liberamos memoria
Set LibroExcel = Nothing
Set PresPP = Nothing
Set ppApp = Nothing
'Activamos nuevamente las alertas
Application.DisplayAlerts = True
End Sub
'NOTA: Marcar referencia (Herramienta -> Referencias...)
' "Microsoft PowerPoint 14.0 Object Library"
Sub TablaDeExcelPP()
Dim LibroExcel As Workbook 'Libro Excel
Dim ppApp As PowerPoint.Application 'Aplicación PP
Dim PresPP As PowerPoint.Presentation 'Presentación PP
Dim DirLibroExcel As String 'Dirección Libro Excel
Dim DirPresPP As String 'Dirección Presentación PP
'Desactivamos las alertas
Application.DisplayAlerts = False
'Indicamos la ubicación del Libro de Excel y Presentación PP
DirLibroExcel = "D:\Pruebas\Libro Excel.xlsx"
DirPresPP = "D:\Pruebas\Presentación PP.pptx"
'Se abre el Powerpoint si no estuviera abierto
If ppApp Is Nothing Then Set ppApp = New PowerPoint.Application
ppApp.Visible = True
'Abrimos el libro de Excel y la presentación PP
Set LibroExcel = Workbooks.Open(DirLibroExcel)
Set PresPP = ppApp.Presentations.Open(DirPresPP)
'Copiamos la tabla del Libro de Excel
LibroExcel.Sheets("Tabla Origen").Range("A1:F19").Copy
'Pegamos la tabla en la presentación PP
'With PresPP.Slides(2).Shapes.PasteSpecial(link:=True) 'Vinculado
With PresPP.Slides(2).Shapes.PasteSpecial(2) 'Imagen
.LockAspectRatio = msoFalse
.Height = 400 'Largo
.Width = 600 'Ancho
.Left = 50 'Posición horizontal
.Top = 80 'Posición vertical
End With
'Cerramos el Libro Excel sin guardar cambios
LibroExcel.Close False
'Cerramos la Presentació PP guardando los cambios
PresPP.Save
'PresPP.Close
'Liberamos memoria
Set LibroExcel = Nothing
Set PresPP = Nothing
Set ppApp = Nothing
'Activamos nuevamente las alertas
Application.DisplayAlerts = True
End Sub
Ejemplo para pasar un gráfico de un libro Excel a una presentación PP:
'NOTA: Marcar referencia (Herramienta -> Referencias...)
' "Microsoft PowerPoint 14.0 Object Library"
Sub GraficoDeExcelPP()
Dim LibroExcel As Workbook 'Libro Excel
Dim ppApp As PowerPoint.Application 'Aplicación PP
Dim PresPP As PowerPoint.Presentation 'Presentación PP
Dim DirLibroExcel As String 'Dirección Libro Excel
Dim DirPresPP As String 'Dirección Presentación PP
'Desactivamos las alertas
Application.DisplayAlerts = False
'Indicamos la ubicación del Libro de Excel y Presentación PP
DirLibroExcel = "D:\Pruebas\Libro Excel.xlsx"
DirPresPP = "D:\Pruebas\Presentación PP.pptx"
'Se abre el Powerpoint si no estuviera abierto
If ppApp Is Nothing Then Set ppApp = New PowerPoint.Application
ppApp.Visible = True
'Abrimos el libro de Excel y la presentación PP
Set LibroExcel = Workbooks.Open(DirLibroExcel)
Set PresPP = ppApp.Presentations.Open(DirPresPP)
'Copiamos la tabla del Libro de Excel
LibroExcel.Sheets("Gráfico Origen").ChartObjects(1).Activate
ActiveChart.ChartArea.Copy
'Pegamos la tabla en la presentación PP
'With PresPP.Slides(3).Shapes.PasteSpecial(link:=True) 'Vinculado
With PresPP.Slides(3).Shapes.PasteSpecial(2) 'Imagen
.LockAspectRatio = msoFalse
.Height = 400 'Largo
.Width = 600 'Ancho
.Left = 50 'Posición horizontal
.Top = 80 'Posición vertical
End With
'Cerramos el Libro Excel sin guardar cambios
LibroExcel.Close False
'Cerramos la Presentació PP guardando los cambios
PresPP.Save
'PresPP.Close
'Liberamos memoria
Set LibroExcel = Nothing
Set PresPP = Nothing
Set ppApp = Nothing
'Activamos nuevamente las alertas
Application.DisplayAlerts = True
End Sub

No hay comentarios:
Publicar un comentario