Issues using copy-pasting macro from Excel to text box in PPT
Hello all,
I needed a macro to copy text contained in Excel cells to text boxes in a PPT slide, with a new slide created for each line in the Excel file. I found the following PPT macro online:
Code:
Sub CreateSlides()
'Run the OpenFile function to get an Open File dialog box. It returns a String containing the file and path.
strFilePath = OpenFile()
'Open the Excel file
Set objWorkbook = Excel.Application.Workbooks.Open(strFilePath)
'Grab the first Worksheet in the Workbook
Set objWorksheet = objWorkbook.Worksheets(1)
'Loop through each used row in Column A
For i = 1 To objWorksheet.Range("A65536").End(xlUp).Row
'Copy the first slide and paste at the end of the presentation
ActivePresentation.Slides(1).Copy
ActivePresentation.Slides.Paste (ActivePresentation.Slides.Count + 1)
'Change the text of the first text box on the slide.
ActivePresentation.Slides(ActivePresentation.Slides.Count).Shapes(1).TextFrame.TextRange.Text = objWorksheet.Cells(i, 1).Value
ActivePresentation.Slides(ActivePresentation.Slides.Count).Shapes(2).TextFrame.TextRange.Text = objWorksheet.Cells(i, 2).Value
ActivePresentation.Slides(ActivePresentation.Slides.Count).Shapes(3).TextFrame.TextRange.Text = objWorksheet.Cells(i, 3).Value
Next
End Sub
This method works for a slide or two, then throws the following error:
Quote:
Run-time error '-2147188160 (80048240)': Slides (unknown member): invalid request. Clipboard is empty or contains data which may not be pasted here.
Debugging shows this line as the culprit:
Code:
ActivePresentation.Slides.Paste (ActivePresentation.Slides.Count + 1)
I've tried looking up the error code online, but none of the solutions proposed seem to work.
Do you know what's wrong here?
Thanks for your help,
-Isa