You are on page 1of 4

Gigihggiggt7997p;

Gmwngm gmf g w gw hnw hnw hwDim rng As Excel.Range


Dim sht As Excel.Worksheet

Set rng = Selection

pp.Visible = True
If pp.Presentations.Count = 0 Then
Set ppt = pp.Presentations.Add
Else
Set ppt = pp.ActivePresentation
End If

Set sld = ppt.Slides.Add(1, ppLayoutTitleOnly)


Set shpTable = sld.Shapes.AddTable(rng.Rows.Count, rng.Columns.Count)
For i = 1 To rng.Rows.Count
For j = 1 To rng.Columns.Count
shpTable.Table.Cell(i, j).Shape.TextFrame.TextRange.Text = _
rng.Cells(i, j).Text
Next
Next

For i = 1 To rng.Rows.Count
For j = 1 To rng.Columns.Count
If (rng.Cells(i, j).MergeArea.Cells.Count > 1) And _
(rng.Cells(i, j).Text <> "") Then
shpTable.Table.Cell(i, j).Merge _
shpTable.Table.Cell(i + rng.Cells(i,
j).MergeArea.Rows.Count - 1, _
j + rng.Cells(i, j).MergeArea.Columns.Count - 1)
End If
Next
Next

sld.Shapes.Title.TextFrame.TextRange.Text = _
rng.Worksheet.Name & " - " & rng.Address

End Sub

'# Code by Mahipal Padigela


''# Open Microsoft Powerpoint,Choose/Insert a Table type Slide(No.4), then
double click to add a...
''# ...Table(3 Cols & 2 Rows) then rename the Table to "Table1", Save and
Close the Presentation
''# Open Microsoft Excel, add some test data to Sheet1(This example assumes
that you have some data in...
''# ... Rows 1,2 and Columns 1,2,3)
''# Open VBA editor(Alt+F11),Insert a Module and Paste the following code
in to the code window
''# Reference 'Microsoft Powerpoint Object Library' (VBA IDE-->tools--
>references)
''# Change "strPresPath" with full path of the Powerpoint Presentation
created earlier.
''# Change "strNewPresPath" to where you want to save the new Presnetation
to be created later
''# Close VB Editor and run this Macro from Excel window(Alt+F8)

Dim oPPTApp As PowerPoint.Application


Dim oPPTShape As PowerPoint.Shape
Dim oPPTFile As PowerPoint.Presentation
Dim SlideNum As Integer
Sub PPTableMacro()
Dim strPresPath As String, strExcelFilePath As String, strNewPresPath
As String
strPresPath = "H:\PowerPoint\Presentation1.ppt"
strNewPresPath = "H:\PowerPoint\new1.ppt"

Set oPPTApp = CreateObject("PowerPoint.Application")


oPPTApp.Visible = msoTrue
Set oPPTFile = oPPTApp.Presentations.Open(strPresPath)
SlideNum = 1
oPPTFile.Slides(SlideNum).Select
Set oPPTShape = oPPTFile.Slides(SlideNum).Shapes("Table1")

Sheets("Sheet1").Activate
oPPTShape.Table.Cell(1, 1).Shape.TextFrame.TextRange.Text = Cells(1,
1).Text
oPPTShape.Table.Cell(1, 2).Shape.TextFrame.TextRange.Text = Cells(1,
2).Text
oPPTShape.Table.Cell(1, 3).Shape.TextFrame.TextRange.Text = Cells(1,
3).Text
oPPTShape.Table.Cell(2, 1).Shape.TextFrame.TextRange.Text = Cells(2,
1).Text
oPPTShape.Table.Cell(2, 2).Shape.TextFrame.TextRange.Text = Cells(2,
2).Text
oPPTShape.Table.Cell(2, 3).Shape.TextFrame.TextRange.Text = Cells(2,
3).Text

oPPTFile.SaveAs strNewPresPath
oPPTFile.Close
oPPTApp.Quit

Set oPPTShape = Nothing


Set oPPTFile = Nothing
Set oPPTApp = Nothing

MsgBox "Presentation Created", vbOKOnly + vbInformation


End Sub

Sub ExcelRangeToPowerPoint()
'PURPOSE: Copy/Paste An Excel Range Into a New PowerPoint Presentation
'SOURCE: www.TheSpreadsheetGuru.com

Dim rng As Range


Dim PowerPointApp As Object
Dim myPresentation As Object
Dim mySlide As Object
Dim myShape As Object

'Copy Range from Excel


Set rng = ThisWorkbook.ActiveSheet.Range("A1:C12")
'Create an Instance of PowerPoint
On Error Resume Next

'Is PowerPoint already opened?


Set PowerPointApp = GetObject(class:="PowerPoint.Application")

'Clear the error between errors


Err.Clear

'If PowerPoint is not already open then open PowerPoint


If PowerPointApp Is Nothing Then Set PowerPointApp =
CreateObject(class:="PowerPoint.Application")

'Handle if the PowerPoint Application is not found


If Err.Number = 429 Then
MsgBox "PowerPoint could not be found, aborting."
Exit Sub
End If

On Error GoTo 0

'Optimize Code
Application.ScreenUpdating = False

'Create a New Presentation


Set myPresentation = PowerPointApp.Presentations.Add

'Add a slide to the Presentation


Set mySlide = myPresentation.Slides.Add(1, 11) '11 = ppLayoutTitleOnly

'Copy Excel Range


rng.Copy

'Paste to PowerPoint and position


mySlide.Shapes.PasteSpecial DataType:=2 '2 = ppPasteEnhancedMetafile
Set myShape = mySlide.Shapes(mySlide.Shapes.Count)

'Set position:
myShape.Left = 66
myShape.Top = 152

'Make PowerPoint Visible and Active


PowerPointApp.Visible = True
PowerPointApp.Activate
'Clear The Clipboard
Application.CutCopyMode = False

End Sub

Sub RemoveBlankRows()

'PURPOSE: Deletes any row with blank cells located inside a designated range

'SOURCE: www.TheSpreadsheetGuru.com

Dim rng As Range

Set rng = Range("B:Q").SpecialCells(xlCellTypeBlanks)

rng.EntireRow.Delete

End Sub

Sub FillBlanks()

Columns("E:E").Select

Selection.SpecialCells(xlCellTypeBlanks).Select

Selection.FormulaR1C1 = "=R[-1]C"

End Sub

You might also like