Importing Excel data into PowerPoint slides - Run-time error '-2147024809 (80070057)': The specified value is out of rangeExporting Excel data into a PowerPoint presentationSleep function error 453Update existing PowerPoint from data in ExcelError in Code to Paste / Copy Shapes from Excel to PowerPoint VBAPowerpoint VBA - Copying Text box AND Text to all slides (w/o selecting)How to automate moving Excel content and graphs into Powerpoint when links aren't an option?How can I edit a PowerPoint presentation embedded in Excel using Excel VBA and userformPaste a range from Excel in to PowerPoint whilst keeping formattingPasting multiple shapes in a Powerpoint Slide using VBA-ExcelUnable to copy Excel Map Chart using VBA
What do I do when a student working in my lab "ghosts" me?
"I you already know": is this proper English?
Is there a reason why I should not use the HaveIBeenPwned API to warn users about exposed passwords?
What exactly makes a General Products hull nearly indestructible?
How were the LM astronauts supported during the moon landing and ascent? What were the max G's on them during these phases?
Grid/table with lots of buttons
What are the exact meanings of roll, pitch and yaw?
Is it legal for private citizens to "impound" e-scooters?
Why did Saturn V not head straight to the moon?
How to judge a Ph.D. applicant that arrives "out of thin air"
USA: Can a witness take the 5th to avoid perjury?
What does ものと見て, mean?
Spoken encryption
Creating Darkness
Print sums of all subsets
What is the difference between 1/3, 1/2, and full casters?
How can I stop myself from micromanaging other PCs' actions?
How can I make sure my players' decisions have consequences?
Why can't my huge trees be chopped down?
This message is flooding my syslog, how to find where it comes from?
What was the rationale behind 36 bit computer architectures?
Strange Cron Job takes up 100% of CPU Ubuntu 18 LTS Server
How may I concisely assign different values to a variable, depending on another variable?
expansion with *.txt in the shell doesn't work if no .txt file exists
Importing Excel data into PowerPoint slides - Run-time error '-2147024809 (80070057)': The specified value is out of range
Exporting Excel data into a PowerPoint presentationSleep function error 453Update existing PowerPoint from data in ExcelError in Code to Paste / Copy Shapes from Excel to PowerPoint VBAPowerpoint VBA - Copying Text box AND Text to all slides (w/o selecting)How to automate moving Excel content and graphs into Powerpoint when links aren't an option?How can I edit a PowerPoint presentation embedded in Excel using Excel VBA and userformPaste a range from Excel in to PowerPoint whilst keeping formattingPasting multiple shapes in a Powerpoint Slide using VBA-ExcelUnable to copy Excel Map Chart using VBA
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am trying to load data from an Excel rows into PowerPoint slides, but the code breaks on the last line and gives the error
'Value out of range'.
This is the first time that I'm working with VBA so I might be making a really stupid mistake but I can't get it fixed myself.
I am using the script from this site
https://www.craig-tolley.co.uk/2011/06/08/vba-create-powerpoint-slide-for-each-row-in-excel-workbook/
I have tried breaking up the line of code and it seems like the error is caused by the .Textrange.Text part, but this is used in loads of other examples just fine?
Opening the Excel and loading the values WS.Cells(i, 1).Value works, I tried this with Msgbox().
So the error seems to be with selecting and filling the text boxes / shapes (just one in this example). I have added empty text boxes via the developer menu besides the normal text boxes that were already there, and I have renamed them in the Selection Pane.
Can someone tell me what I'm doing wrong?
Sub ReferentieSlides()
'Open the Excel workbook. Change the filename here.
Dim OWB As New Excel.Workbook
Set OWB = Excel.Application.Workbooks.Open("C:UsersMeFile.xlsm")
'Grab the first Worksheet in the Workbook
Dim WS As Excel.Worksheet
Set WS = OWB.Worksheets(1)
'Loop through each used row in Column A
For i = 1 To WS.Range("A10").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 = WS.Cells(i, 1).Value
Next
End Sub
Code with fixes tried so far:
#If VBA7 Then
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr) 'For 64 Bit Systems
#Else
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'For 32 Bit Systems
#End If
Sub ReferentieSlides()
'Open the Excel workbook. Change the filename here.
Dim OWB As New Excel.Workbook
'Set OWB = Excel.Application.Workbooks.Open("C:UsersIngeSchenkBoer & Croon Management BVManagement Solutions - BankMacro Referenties.xlsm")
Set OWB = Excel.Application.Workbooks.Open("C:UsersIngeSchenkDropboxTest2.xlsx")
'Grab the first Worksheet in the Workbook
Dim WS As Excel.Worksheet
Set WS = OWB.Worksheets(1)
'Define i
Dim i As Long
'Loop through each used row in Column A
For i = 1 To WS.Range("A" & Rows.Count).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)
'Sleep for 10sec
MsgBox "Execution is started"
Sleep 10000 'delay in milliseconds
MsgBox "Execution Resumed"
'Change the text of the first text box on the slide.
ActivePresentation.Slides(ActivePresentation.Slides.Count).Shapes(1).TextFrame.TextRange.Text = WS.Cells(i, 1).Value
Next
End Sub
excel vba powerpoint powerpoint-vba
|
show 2 more comments
I am trying to load data from an Excel rows into PowerPoint slides, but the code breaks on the last line and gives the error
'Value out of range'.
This is the first time that I'm working with VBA so I might be making a really stupid mistake but I can't get it fixed myself.
I am using the script from this site
https://www.craig-tolley.co.uk/2011/06/08/vba-create-powerpoint-slide-for-each-row-in-excel-workbook/
I have tried breaking up the line of code and it seems like the error is caused by the .Textrange.Text part, but this is used in loads of other examples just fine?
Opening the Excel and loading the values WS.Cells(i, 1).Value works, I tried this with Msgbox().
So the error seems to be with selecting and filling the text boxes / shapes (just one in this example). I have added empty text boxes via the developer menu besides the normal text boxes that were already there, and I have renamed them in the Selection Pane.
Can someone tell me what I'm doing wrong?
Sub ReferentieSlides()
'Open the Excel workbook. Change the filename here.
Dim OWB As New Excel.Workbook
Set OWB = Excel.Application.Workbooks.Open("C:UsersMeFile.xlsm")
'Grab the first Worksheet in the Workbook
Dim WS As Excel.Worksheet
Set WS = OWB.Worksheets(1)
'Loop through each used row in Column A
For i = 1 To WS.Range("A10").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 = WS.Cells(i, 1).Value
Next
End Sub
Code with fixes tried so far:
#If VBA7 Then
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr) 'For 64 Bit Systems
#Else
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'For 32 Bit Systems
#End If
Sub ReferentieSlides()
'Open the Excel workbook. Change the filename here.
Dim OWB As New Excel.Workbook
'Set OWB = Excel.Application.Workbooks.Open("C:UsersIngeSchenkBoer & Croon Management BVManagement Solutions - BankMacro Referenties.xlsm")
Set OWB = Excel.Application.Workbooks.Open("C:UsersIngeSchenkDropboxTest2.xlsx")
'Grab the first Worksheet in the Workbook
Dim WS As Excel.Worksheet
Set WS = OWB.Worksheets(1)
'Define i
Dim i As Long
'Loop through each used row in Column A
For i = 1 To WS.Range("A" & Rows.Count).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)
'Sleep for 10sec
MsgBox "Execution is started"
Sleep 10000 'delay in milliseconds
MsgBox "Execution Resumed"
'Change the text of the first text box on the slide.
ActivePresentation.Slides(ActivePresentation.Slides.Count).Shapes(1).TextFrame.TextRange.Text = WS.Cells(i, 1).Value
Next
End Sub
excel vba powerpoint powerpoint-vba
Can you putDebug.Print ActivePresentation.Slides(ActivePresentation.Slides.Count).Shapes.Counton the line below your.Pasteline and see what is returned to the immediate window? Also, is it breaking on your first iteration of the loop, or a specific one? Excel to PowerPoint is notoriously clunky, you may just need to add some buffer time in your loop.
– dwirony
Mar 26 at 16:41
(Also, please declare all variables. AddDim i as Longto the sub before you calli. Additionally, if you have information inA1:A10, your loop is just going to go from row1to1...is that what you want? I think you wantws.Range("A" & rows.count).End(xlUp).Row?
– BruceWayne
Mar 26 at 16:41
@dwinory That formula counts 12 shapes on that slide. The code breaks on the first iteration: a new slide is created, but no information is added. I tried adding a 10-second Sleep function before pasting the info, but the error still showed.
– Inge
Mar 27 at 9:54
@BruceWayne I have also addedDim i As Longbefore opening the For-loop and have adjusted the ws.Range to your improvement, but to no avail :(
– Inge
Mar 27 at 10:02
Why is the Excel file you are opening a Macro-enabled file? Will it have a macro that runs?
– mooseman
Apr 12 at 19:11
|
show 2 more comments
I am trying to load data from an Excel rows into PowerPoint slides, but the code breaks on the last line and gives the error
'Value out of range'.
This is the first time that I'm working with VBA so I might be making a really stupid mistake but I can't get it fixed myself.
I am using the script from this site
https://www.craig-tolley.co.uk/2011/06/08/vba-create-powerpoint-slide-for-each-row-in-excel-workbook/
I have tried breaking up the line of code and it seems like the error is caused by the .Textrange.Text part, but this is used in loads of other examples just fine?
Opening the Excel and loading the values WS.Cells(i, 1).Value works, I tried this with Msgbox().
So the error seems to be with selecting and filling the text boxes / shapes (just one in this example). I have added empty text boxes via the developer menu besides the normal text boxes that were already there, and I have renamed them in the Selection Pane.
Can someone tell me what I'm doing wrong?
Sub ReferentieSlides()
'Open the Excel workbook. Change the filename here.
Dim OWB As New Excel.Workbook
Set OWB = Excel.Application.Workbooks.Open("C:UsersMeFile.xlsm")
'Grab the first Worksheet in the Workbook
Dim WS As Excel.Worksheet
Set WS = OWB.Worksheets(1)
'Loop through each used row in Column A
For i = 1 To WS.Range("A10").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 = WS.Cells(i, 1).Value
Next
End Sub
Code with fixes tried so far:
#If VBA7 Then
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr) 'For 64 Bit Systems
#Else
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'For 32 Bit Systems
#End If
Sub ReferentieSlides()
'Open the Excel workbook. Change the filename here.
Dim OWB As New Excel.Workbook
'Set OWB = Excel.Application.Workbooks.Open("C:UsersIngeSchenkBoer & Croon Management BVManagement Solutions - BankMacro Referenties.xlsm")
Set OWB = Excel.Application.Workbooks.Open("C:UsersIngeSchenkDropboxTest2.xlsx")
'Grab the first Worksheet in the Workbook
Dim WS As Excel.Worksheet
Set WS = OWB.Worksheets(1)
'Define i
Dim i As Long
'Loop through each used row in Column A
For i = 1 To WS.Range("A" & Rows.Count).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)
'Sleep for 10sec
MsgBox "Execution is started"
Sleep 10000 'delay in milliseconds
MsgBox "Execution Resumed"
'Change the text of the first text box on the slide.
ActivePresentation.Slides(ActivePresentation.Slides.Count).Shapes(1).TextFrame.TextRange.Text = WS.Cells(i, 1).Value
Next
End Sub
excel vba powerpoint powerpoint-vba
I am trying to load data from an Excel rows into PowerPoint slides, but the code breaks on the last line and gives the error
'Value out of range'.
This is the first time that I'm working with VBA so I might be making a really stupid mistake but I can't get it fixed myself.
I am using the script from this site
https://www.craig-tolley.co.uk/2011/06/08/vba-create-powerpoint-slide-for-each-row-in-excel-workbook/
I have tried breaking up the line of code and it seems like the error is caused by the .Textrange.Text part, but this is used in loads of other examples just fine?
Opening the Excel and loading the values WS.Cells(i, 1).Value works, I tried this with Msgbox().
So the error seems to be with selecting and filling the text boxes / shapes (just one in this example). I have added empty text boxes via the developer menu besides the normal text boxes that were already there, and I have renamed them in the Selection Pane.
Can someone tell me what I'm doing wrong?
Sub ReferentieSlides()
'Open the Excel workbook. Change the filename here.
Dim OWB As New Excel.Workbook
Set OWB = Excel.Application.Workbooks.Open("C:UsersMeFile.xlsm")
'Grab the first Worksheet in the Workbook
Dim WS As Excel.Worksheet
Set WS = OWB.Worksheets(1)
'Loop through each used row in Column A
For i = 1 To WS.Range("A10").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 = WS.Cells(i, 1).Value
Next
End Sub
Code with fixes tried so far:
#If VBA7 Then
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr) 'For 64 Bit Systems
#Else
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'For 32 Bit Systems
#End If
Sub ReferentieSlides()
'Open the Excel workbook. Change the filename here.
Dim OWB As New Excel.Workbook
'Set OWB = Excel.Application.Workbooks.Open("C:UsersIngeSchenkBoer & Croon Management BVManagement Solutions - BankMacro Referenties.xlsm")
Set OWB = Excel.Application.Workbooks.Open("C:UsersIngeSchenkDropboxTest2.xlsx")
'Grab the first Worksheet in the Workbook
Dim WS As Excel.Worksheet
Set WS = OWB.Worksheets(1)
'Define i
Dim i As Long
'Loop through each used row in Column A
For i = 1 To WS.Range("A" & Rows.Count).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)
'Sleep for 10sec
MsgBox "Execution is started"
Sleep 10000 'delay in milliseconds
MsgBox "Execution Resumed"
'Change the text of the first text box on the slide.
ActivePresentation.Slides(ActivePresentation.Slides.Count).Shapes(1).TextFrame.TextRange.Text = WS.Cells(i, 1).Value
Next
End Sub
excel vba powerpoint powerpoint-vba
excel vba powerpoint powerpoint-vba
edited Mar 27 at 10:08
Inge
asked Mar 26 at 16:28
IngeInge
62 bronze badges
62 bronze badges
Can you putDebug.Print ActivePresentation.Slides(ActivePresentation.Slides.Count).Shapes.Counton the line below your.Pasteline and see what is returned to the immediate window? Also, is it breaking on your first iteration of the loop, or a specific one? Excel to PowerPoint is notoriously clunky, you may just need to add some buffer time in your loop.
– dwirony
Mar 26 at 16:41
(Also, please declare all variables. AddDim i as Longto the sub before you calli. Additionally, if you have information inA1:A10, your loop is just going to go from row1to1...is that what you want? I think you wantws.Range("A" & rows.count).End(xlUp).Row?
– BruceWayne
Mar 26 at 16:41
@dwinory That formula counts 12 shapes on that slide. The code breaks on the first iteration: a new slide is created, but no information is added. I tried adding a 10-second Sleep function before pasting the info, but the error still showed.
– Inge
Mar 27 at 9:54
@BruceWayne I have also addedDim i As Longbefore opening the For-loop and have adjusted the ws.Range to your improvement, but to no avail :(
– Inge
Mar 27 at 10:02
Why is the Excel file you are opening a Macro-enabled file? Will it have a macro that runs?
– mooseman
Apr 12 at 19:11
|
show 2 more comments
Can you putDebug.Print ActivePresentation.Slides(ActivePresentation.Slides.Count).Shapes.Counton the line below your.Pasteline and see what is returned to the immediate window? Also, is it breaking on your first iteration of the loop, or a specific one? Excel to PowerPoint is notoriously clunky, you may just need to add some buffer time in your loop.
– dwirony
Mar 26 at 16:41
(Also, please declare all variables. AddDim i as Longto the sub before you calli. Additionally, if you have information inA1:A10, your loop is just going to go from row1to1...is that what you want? I think you wantws.Range("A" & rows.count).End(xlUp).Row?
– BruceWayne
Mar 26 at 16:41
@dwinory That formula counts 12 shapes on that slide. The code breaks on the first iteration: a new slide is created, but no information is added. I tried adding a 10-second Sleep function before pasting the info, but the error still showed.
– Inge
Mar 27 at 9:54
@BruceWayne I have also addedDim i As Longbefore opening the For-loop and have adjusted the ws.Range to your improvement, but to no avail :(
– Inge
Mar 27 at 10:02
Why is the Excel file you are opening a Macro-enabled file? Will it have a macro that runs?
– mooseman
Apr 12 at 19:11
Can you put
Debug.Print ActivePresentation.Slides(ActivePresentation.Slides.Count).Shapes.Count on the line below your .Paste line and see what is returned to the immediate window? Also, is it breaking on your first iteration of the loop, or a specific one? Excel to PowerPoint is notoriously clunky, you may just need to add some buffer time in your loop.– dwirony
Mar 26 at 16:41
Can you put
Debug.Print ActivePresentation.Slides(ActivePresentation.Slides.Count).Shapes.Count on the line below your .Paste line and see what is returned to the immediate window? Also, is it breaking on your first iteration of the loop, or a specific one? Excel to PowerPoint is notoriously clunky, you may just need to add some buffer time in your loop.– dwirony
Mar 26 at 16:41
(Also, please declare all variables. Add
Dim i as Long to the sub before you call i. Additionally, if you have information in A1:A10, your loop is just going to go from row 1 to 1...is that what you want? I think you want ws.Range("A" & rows.count).End(xlUp).Row?– BruceWayne
Mar 26 at 16:41
(Also, please declare all variables. Add
Dim i as Long to the sub before you call i. Additionally, if you have information in A1:A10, your loop is just going to go from row 1 to 1...is that what you want? I think you want ws.Range("A" & rows.count).End(xlUp).Row?– BruceWayne
Mar 26 at 16:41
@dwinory That formula counts 12 shapes on that slide. The code breaks on the first iteration: a new slide is created, but no information is added. I tried adding a 10-second Sleep function before pasting the info, but the error still showed.
– Inge
Mar 27 at 9:54
@dwinory That formula counts 12 shapes on that slide. The code breaks on the first iteration: a new slide is created, but no information is added. I tried adding a 10-second Sleep function before pasting the info, but the error still showed.
– Inge
Mar 27 at 9:54
@BruceWayne I have also added
Dim i As Long before opening the For-loop and have adjusted the ws.Range to your improvement, but to no avail :(– Inge
Mar 27 at 10:02
@BruceWayne I have also added
Dim i As Long before opening the For-loop and have adjusted the ws.Range to your improvement, but to no avail :(– Inge
Mar 27 at 10:02
Why is the Excel file you are opening a Macro-enabled file? Will it have a macro that runs?
– mooseman
Apr 12 at 19:11
Why is the Excel file you are opening a Macro-enabled file? Will it have a macro that runs?
– mooseman
Apr 12 at 19:11
|
show 2 more comments
1 Answer
1
active
oldest
votes
Due to David Zemens comment about this being a PPT macro, I have changed this answer. The problem is using the End(xlup) function that doesn't work in PPT
This did work for me, but the opening excel can be done your way if it works for you.
Sub ReferentieSlides()
'Open the Excel workbook. Change the filename here.
Dim OWB As Object
Set OWB = CreateObject("T:usermeFile.xlsm")
'Grab the first Worksheet in the Workbook
Set WS = OWB.Sheets(1)
Set PPTObj = ActivePresentation 'Get the presentation that was opened
'Loop through each used row in Column A
'For i = 1 To WS.Range("A10").End(xlUp).Row
For i = 1 To WS.Range("A1:A10").CurrentRegion.Rows.Count
'Copy the first slide and paste at the end of the presentation
PPTObj.Slides(1).Copy
PPTObj.Slides.Paste (PPTObj.Slides.Count + 1)
'Change the text of the first text box on the slide.
PPTObj.Slides(PPTObj.Slides.Count).Shapes(1).TextFrame.TextRange.Text = WS.Cells(i, 1).Value
Next
End Sub
OP's code appears to be run natively from PPT, hence the instantiation of the Excel.Application instance. Otherwise there would be an Object Variable or With Block not set error on ActivePresentation, as you note.
– David Zemens
Apr 12 at 19:14
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55361965%2fimporting-excel-data-into-powerpoint-slides-run-time-error-2147024809-80070%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Due to David Zemens comment about this being a PPT macro, I have changed this answer. The problem is using the End(xlup) function that doesn't work in PPT
This did work for me, but the opening excel can be done your way if it works for you.
Sub ReferentieSlides()
'Open the Excel workbook. Change the filename here.
Dim OWB As Object
Set OWB = CreateObject("T:usermeFile.xlsm")
'Grab the first Worksheet in the Workbook
Set WS = OWB.Sheets(1)
Set PPTObj = ActivePresentation 'Get the presentation that was opened
'Loop through each used row in Column A
'For i = 1 To WS.Range("A10").End(xlUp).Row
For i = 1 To WS.Range("A1:A10").CurrentRegion.Rows.Count
'Copy the first slide and paste at the end of the presentation
PPTObj.Slides(1).Copy
PPTObj.Slides.Paste (PPTObj.Slides.Count + 1)
'Change the text of the first text box on the slide.
PPTObj.Slides(PPTObj.Slides.Count).Shapes(1).TextFrame.TextRange.Text = WS.Cells(i, 1).Value
Next
End Sub
OP's code appears to be run natively from PPT, hence the instantiation of the Excel.Application instance. Otherwise there would be an Object Variable or With Block not set error on ActivePresentation, as you note.
– David Zemens
Apr 12 at 19:14
add a comment |
Due to David Zemens comment about this being a PPT macro, I have changed this answer. The problem is using the End(xlup) function that doesn't work in PPT
This did work for me, but the opening excel can be done your way if it works for you.
Sub ReferentieSlides()
'Open the Excel workbook. Change the filename here.
Dim OWB As Object
Set OWB = CreateObject("T:usermeFile.xlsm")
'Grab the first Worksheet in the Workbook
Set WS = OWB.Sheets(1)
Set PPTObj = ActivePresentation 'Get the presentation that was opened
'Loop through each used row in Column A
'For i = 1 To WS.Range("A10").End(xlUp).Row
For i = 1 To WS.Range("A1:A10").CurrentRegion.Rows.Count
'Copy the first slide and paste at the end of the presentation
PPTObj.Slides(1).Copy
PPTObj.Slides.Paste (PPTObj.Slides.Count + 1)
'Change the text of the first text box on the slide.
PPTObj.Slides(PPTObj.Slides.Count).Shapes(1).TextFrame.TextRange.Text = WS.Cells(i, 1).Value
Next
End Sub
OP's code appears to be run natively from PPT, hence the instantiation of the Excel.Application instance. Otherwise there would be an Object Variable or With Block not set error on ActivePresentation, as you note.
– David Zemens
Apr 12 at 19:14
add a comment |
Due to David Zemens comment about this being a PPT macro, I have changed this answer. The problem is using the End(xlup) function that doesn't work in PPT
This did work for me, but the opening excel can be done your way if it works for you.
Sub ReferentieSlides()
'Open the Excel workbook. Change the filename here.
Dim OWB As Object
Set OWB = CreateObject("T:usermeFile.xlsm")
'Grab the first Worksheet in the Workbook
Set WS = OWB.Sheets(1)
Set PPTObj = ActivePresentation 'Get the presentation that was opened
'Loop through each used row in Column A
'For i = 1 To WS.Range("A10").End(xlUp).Row
For i = 1 To WS.Range("A1:A10").CurrentRegion.Rows.Count
'Copy the first slide and paste at the end of the presentation
PPTObj.Slides(1).Copy
PPTObj.Slides.Paste (PPTObj.Slides.Count + 1)
'Change the text of the first text box on the slide.
PPTObj.Slides(PPTObj.Slides.Count).Shapes(1).TextFrame.TextRange.Text = WS.Cells(i, 1).Value
Next
End Sub
Due to David Zemens comment about this being a PPT macro, I have changed this answer. The problem is using the End(xlup) function that doesn't work in PPT
This did work for me, but the opening excel can be done your way if it works for you.
Sub ReferentieSlides()
'Open the Excel workbook. Change the filename here.
Dim OWB As Object
Set OWB = CreateObject("T:usermeFile.xlsm")
'Grab the first Worksheet in the Workbook
Set WS = OWB.Sheets(1)
Set PPTObj = ActivePresentation 'Get the presentation that was opened
'Loop through each used row in Column A
'For i = 1 To WS.Range("A10").End(xlUp).Row
For i = 1 To WS.Range("A1:A10").CurrentRegion.Rows.Count
'Copy the first slide and paste at the end of the presentation
PPTObj.Slides(1).Copy
PPTObj.Slides.Paste (PPTObj.Slides.Count + 1)
'Change the text of the first text box on the slide.
PPTObj.Slides(PPTObj.Slides.Count).Shapes(1).TextFrame.TextRange.Text = WS.Cells(i, 1).Value
Next
End Sub
edited Apr 12 at 19:44
answered Apr 12 at 19:10
moosemanmooseman
1,6602 gold badges12 silver badges26 bronze badges
1,6602 gold badges12 silver badges26 bronze badges
OP's code appears to be run natively from PPT, hence the instantiation of the Excel.Application instance. Otherwise there would be an Object Variable or With Block not set error on ActivePresentation, as you note.
– David Zemens
Apr 12 at 19:14
add a comment |
OP's code appears to be run natively from PPT, hence the instantiation of the Excel.Application instance. Otherwise there would be an Object Variable or With Block not set error on ActivePresentation, as you note.
– David Zemens
Apr 12 at 19:14
OP's code appears to be run natively from PPT, hence the instantiation of the Excel.Application instance. Otherwise there would be an Object Variable or With Block not set error on ActivePresentation, as you note.
– David Zemens
Apr 12 at 19:14
OP's code appears to be run natively from PPT, hence the instantiation of the Excel.Application instance. Otherwise there would be an Object Variable or With Block not set error on ActivePresentation, as you note.
– David Zemens
Apr 12 at 19:14
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55361965%2fimporting-excel-data-into-powerpoint-slides-run-time-error-2147024809-80070%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you put
Debug.Print ActivePresentation.Slides(ActivePresentation.Slides.Count).Shapes.Counton the line below your.Pasteline and see what is returned to the immediate window? Also, is it breaking on your first iteration of the loop, or a specific one? Excel to PowerPoint is notoriously clunky, you may just need to add some buffer time in your loop.– dwirony
Mar 26 at 16:41
(Also, please declare all variables. Add
Dim i as Longto the sub before you calli. Additionally, if you have information inA1:A10, your loop is just going to go from row1to1...is that what you want? I think you wantws.Range("A" & rows.count).End(xlUp).Row?– BruceWayne
Mar 26 at 16:41
@dwinory That formula counts 12 shapes on that slide. The code breaks on the first iteration: a new slide is created, but no information is added. I tried adding a 10-second Sleep function before pasting the info, but the error still showed.
– Inge
Mar 27 at 9:54
@BruceWayne I have also added
Dim i As Longbefore opening the For-loop and have adjusted the ws.Range to your improvement, but to no avail :(– Inge
Mar 27 at 10:02
Why is the Excel file you are opening a Macro-enabled file? Will it have a macro that runs?
– mooseman
Apr 12 at 19:11