Skip to main content
Announcements
Global Transformation Awards! Applications are now open. Submit Entry
cancel
Showing results for 
Search instead for 
Did you mean: 
sachingodhania
Contributor III
Contributor III

Export straight/PIVOT to PPT problem

Hi All ,

I am facing some prob in pasting straight/pivot to ppt to a specific slideno, I  am using code as below ,

sub ppt

set objPPT = CreateObject("PowerPoint.Application")

objPPT.Visible = True

Set objPresentation = objPPT.Presentations.Add

ActiveDocument.Sheets("SH01").Activate

Set obj = ActiveDocument.GetSheetObject("CH03")

Set PPSlide = objPresentation.Slides.Add(1,obj.GetObjectType) 

obj.CopyTableToClipboard true

With PPSlide

objPPT.CommandBars.ExecuteMso ("PasteSourceFormatting")

End With

Set obj = ActiveDocument.GetSheetObject("CH04")

Set PPSlide = objPresentation.Slides.Add(2,obj.GetObjectType) 

obj.CopyTableToClipboard true

With PPSlide

objPPT.CommandBars.ExecuteMso ("PasteSourceFormatting")

End With

  End Sub

By this code table always copies on first slide of the PPT and doesn't respect the .left and top Position.

Please let me know if any body had encountered the same issue. Thanks !

Regards,

Sachin

1 Solution

Accepted Solutions
jerem1234
Specialist II
Specialist II

Hi Sachin!

You should try this code:

sub ppt

set objPPT = CreateObject("PowerPoint.Application")

objPPT.Visible = True

Set objPresentation = objPPT.Presentations.Add

For j=1 To 2

  Set PPSlide = objPresentation.Slides.Add(1,12)

next

ActiveDocument.Sheets("SH01").Activate

Set obj = ActiveDocument.GetSheetObject("CH03")

objPresentation.Slides(1).Select

obj.CopyTableToClipboard true

objPPT.CommandBars.ExecuteMso ("PasteSourceFormatting")

Set obj = ActiveDocument.GetSheetObject("CH04")

objPresentation.Slides(2).Select

obj.CopyTableToClipboard true

objPPT.CommandBars.ExecuteMso ("PasteSourceFormatting")

End sub

I found out you don't need the With PPSlide to do Paste Source Formatting since it will paste it in you active slide. So you want to choose the slide you want to paste it on with the statement:

objPresentation.Slides(1).Select


Hope this helps!!

View solution in original post

6 Replies
Chanty4u
MVP
MVP

sachingodhania
Contributor III
Contributor III
Author

Hi Suri,

I have gone through this link. The issue is I am using copytabletoclipboard and its pasting on slide1 only.

Regards,

Sachin

HirisH_V7
Master
Master

Hi,

Check with this code,

Are you exporting two objects or what's the issue can you elaborate!!

Sub ExportPPT 

Set objPPT = CreateObject("PowerPoint.Application") 

objPPT.Visible = True 

Set objPresentation = objPPT.Presentations.open("YourPath\ppt.pptx")'file Path

Set PPSlide = objPresentation.Slides.Add(1,12) 

ActiveDocument.GetSheetObject("CH02").CopyBitmapToClipboard 

PPSlide.Shapes.Paste 

PPSlide.Shapes(PPSlide.Shapes.Count).Top = 150 'This sets the top location of the image 

PPSlide.Shapes(PPSlide.Shapes.Count).Left = 15 'This sets the left location 

PPSlide.Shapes(PPSlide.Shapes.Count).Width = 240 

PPSlide.Shapes(PPSlide.Shapes.Count).Height = 250 

 

 

Set PPSlide = objPresentation.Slides.Add(1,12) 

ActiveDocument.GetSheetObject("CH02").CopyBitmapToClipboard 

PPSlide.Shapes.Paste 

PPSlide.Shapes(PPSlide.Shapes.Count).Top = 150 'This sets the top location of the image 

PPSlide.Shapes(PPSlide.Shapes.Count).Left = 15 'This sets the left location 

PPSlide.Shapes(PPSlide.Shapes.Count).Width = 100 

PPSlide.Shapes(PPSlide.Shapes.Count).Height = 200 

 

Set PPSlide = Nothing 

Set PPPres = Nothing 

Set PPApp = Nothing 

End Sub 

HTH,

Hirish

HirisH
“Aspire to Inspire before we Expire!”
sachingodhania
Contributor III
Contributor III
Author

HI Hirish,

Thanks for code.

I need to user obj.CopyTableToClipboard instead of CopyBitmapToClipboard    in order to copy table.

Regards,

Sachin

jerem1234
Specialist II
Specialist II

Hi Sachin!

You should try this code:

sub ppt

set objPPT = CreateObject("PowerPoint.Application")

objPPT.Visible = True

Set objPresentation = objPPT.Presentations.Add

For j=1 To 2

  Set PPSlide = objPresentation.Slides.Add(1,12)

next

ActiveDocument.Sheets("SH01").Activate

Set obj = ActiveDocument.GetSheetObject("CH03")

objPresentation.Slides(1).Select

obj.CopyTableToClipboard true

objPPT.CommandBars.ExecuteMso ("PasteSourceFormatting")

Set obj = ActiveDocument.GetSheetObject("CH04")

objPresentation.Slides(2).Select

obj.CopyTableToClipboard true

objPPT.CommandBars.ExecuteMso ("PasteSourceFormatting")

End sub

I found out you don't need the With PPSlide to do Paste Source Formatting since it will paste it in you active slide. So you want to choose the slide you want to paste it on with the statement:

objPresentation.Slides(1).Select


Hope this helps!!

sachingodhania
Contributor III
Contributor III
Author

Hi Jeremiah ,

That code pastes exactly on the slide that i want to . Thanks a lot !

On more thing if you can help is I want to make column of table with to content and set font size to 8.

Also the position is working fine in image but for table is not pasting at given co-ordinates.

Regards,

Sachin