0

I'm currently trying to create a calendar in powerpoint using powershell. All I want to do is insert a table into a powerpoint slide. This table is representing the month of January, it contains the days of the week etc.

I did some research and came across this.

This is VB script, so i tried to "create its equivalent" in powershell:

EDIT3: I was finally able to copy my table from Excel and paste it into my powerpoint slide using this code:

#Create an instance of Excel.
$xl=New-Object -ComObject "Excel.Application"
$xl.Visible = $True

#Open the Excel file containing the table. 
$wb = $xl.workbooks.open("C:\January.xls")
$ws = $wb.ActiveSheet

#Select the table.
$range = $ws.range("A1:G7")
$range.select()

#Copy the table to the clipboard.
$range.copyPicture()

#Create an instance of Powerpoint.
$objPPT = New-Object -ComObject "Powerpoint.Application"
$objPPT.Visible ='Msotrue'

#Add a slide to the presentation.    
$project = $objPPT.Presentations.Add()
$slide  = $project.Slides.Add(1, 1)

#Paste the table into the slide.
$shape = $slide.Shapes.Paste()

#Position the table.
$shape.Left = 50
$shape.Top = 150
$shape.Width = 300
$shape.Height = 168

Thanks to those who have helped me here and on #powershell

4
  • Show the code that you created in trying to convert the VBS to PowerShell. Commented Oct 24, 2013 at 19:56
  • @arloc I didn't do much since i'm kind of new to powershell, but here's what i tried: pastebin.com/8sqQptFb Commented Oct 24, 2013 at 20:18
  • And in what way did you "not succeed"? Describe what your end goal is, what you did, what you got, and where exactly you're stuck/things aren't working as expected. There's at least one bug I see in how you're handling app visibility (hint: compare $objPPT.Visible and $xl.Visible) Commented Oct 25, 2013 at 0:26
  • @alroc Thank you for replying to me. I made a few changes to the code I was trying to "convert": pastebin.com/khvL0Lm7 If I use this script to paste my table into a word document, this is what I get: i.imgur.com/GsnHvwE.jpg a nice table that I can move and resize, this is exactly what I need to do. However, If I use the script to paste the table into a powerpoint slide I get an error (refer to the original poste, above). Also, I did compare $objPPT.Visible and $xl.Visible but i chose to use 'Msotrue' on purpose. I get an error if I don't do so. Commented Oct 25, 2013 at 5:28

2 Answers 2

0

I saw your question in the channel. This worked for me:

$presentation = $ppt.Presentations.Open($ifile)
$sl = $presentation.Slides.Add(1, $ppLayoutBlank) 
$shape = $sl.shapes.paste()
Sign up to request clarification or add additional context in comments.

1 Comment

Hi, thanks for replying, it worked but I had to use $range.copyPicture() instead of $range.copy().
0

I think you can use this:

# Optionally, make sure you're on the last slide:
$ppt.ActiveWindow.View.GotoSlide( $ppt.ActivePresentation.Slides.Count )

# Specify the 
$ppt.ActiveWindow.View.PasteSpecial( "ppPasteOLEObject", "msoFalse",  "", 0, "", "msoFalse")

See the MSDN Interop Docs and thanks to this example: Paste Excel Chart into Powerpoint using VBA

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.