Chunk
11-29-2018, 08:38 AM
Good morning VBA Masters,
I am currently working on a process that opens a PowerPointPresentation, copies and saves the slides as a jpg then opens a Word Documentand changes the .Picture property of the ActiveX Image Control, of which thereare 17.
The code I have opens the PowerPoint, copies and saves theslides correctly, then opens the Word document and then I receive a Run-timeerror, Method ‘Picture’ of object ‘Image’ failed.
Currently I am just trying to get one picture to change,with no success.
Below is the code that I currently have and attached are examplesof the Excel and Word files I am using.
Sub Imp_Res_Grphs()
Dim pptApp AsObject
Dim pptFile AsString
Dim pptPres AsObject
Dim wrdApp AsObject
Dim wrdFile AsObject
pptFile ="C:\Users\Chunk\Reports\str1_totals.pptx"
Set pptApp =CreateObject("PowerPoint.Application")
pptApp.Visible = True
Set pptPres =pptApp.Presentations.Open(pptFile)
'Exports slides from Powerpoint and saves as jpg file
With pptPres
.Slides(2).Export"C:\Users\Chunk\Reports\Slides\" &"all_stores_ttl.jpg", "JPG"
.Slides(3).Export "C:\Users\Chunk\Reports\Slides\" &"str1_depa.jpg", "JPG"
.Slides(4).Export "C:\Users\Chunk\Reports\Slides\" &"str1_depb.jpg", "JPG"
.Slides(5).Export "C:\Users\Chunk\Reports\Slides\" &"str1_depc.jpg", "JPG"
.Slides(6).Export "C:\Users\Chunk\Reports\Slides\" &"str1_depd.jpg", "JPG"
.Slides(7).Export "C:\Users\Chunk\Reports\Slides\" &"str1_depe.jpg", "JPG"
.Slides(8).Export "C:\Users\Chunk\Reports\Slides\" &"str1_depf.jpg", "JPG"
.Slides(9).Export "C:\Users\Chunk\Reports\Slides\" &"str1_depg.jpg", "JPG"
.Slides(10).Export "C:\Users\Chunk\Reports\Slides\" &"str1_deph.jpg", "JPG"
.Slides(11).Export "C:\Users\Chunk\Reports\Slides\" &"str1_depi.jpg", "JPG"
.Slides(12).Export "C:\Users\Chunk\Reports\Slides\" &"str1_depk.jpg", "JPG"
.Slides(13).Export "C:\Users\Chunk\Reports\Slides\" &"str1_depl.jpg", "JPG"
.Slides(14).Export "C:\Users\Chunk\Reports\Slides\" &"str1_depm.jpg", "JPG"
.Slides(15).Export "C:\Users\Chunk\Reports\Slides\" &"str1_depn.jpg", "JPG"
.Slides(16).Export"C:\Users\Chunk\Reports\Slides\" & "str1_depo.jpg","JPG"
.Slides(17).Export "C:\Users\Chunk\Reports\Slides\" &"str1_depp.jpg", "JPG"
.Slides(18).Export "C:\Users\Chunk\Reports\Slides\" &"str1_ttl.jpg", "JPG"
End With
'closes powerpoint
pptPres.Close
Set pptPres =Nothing
pptApp.Quit
Set pptApp =Nothing
'Open Worddocument and import graphs
Set wrdApp =CreateObject("Word.Application")
wrdApp.Visible =True
Set wrdFile =wrdApp.Documents.Open("C:\Users\Chunk\Reports\Store1_Weekly_Report.docm")
With wrdFile
.Image1.Picture =LoadPicture("C:\Users\Chunk\Reports\Slides\tot_prod.jpg")
End With
End Sub
Any help/direction you can give is greatly appreciated.
Sincerely,
Chunk
I am currently working on a process that opens a PowerPointPresentation, copies and saves the slides as a jpg then opens a Word Documentand changes the .Picture property of the ActiveX Image Control, of which thereare 17.
The code I have opens the PowerPoint, copies and saves theslides correctly, then opens the Word document and then I receive a Run-timeerror, Method ‘Picture’ of object ‘Image’ failed.
Currently I am just trying to get one picture to change,with no success.
Below is the code that I currently have and attached are examplesof the Excel and Word files I am using.
Sub Imp_Res_Grphs()
Dim pptApp AsObject
Dim pptFile AsString
Dim pptPres AsObject
Dim wrdApp AsObject
Dim wrdFile AsObject
pptFile ="C:\Users\Chunk\Reports\str1_totals.pptx"
Set pptApp =CreateObject("PowerPoint.Application")
pptApp.Visible = True
Set pptPres =pptApp.Presentations.Open(pptFile)
'Exports slides from Powerpoint and saves as jpg file
With pptPres
.Slides(2).Export"C:\Users\Chunk\Reports\Slides\" &"all_stores_ttl.jpg", "JPG"
.Slides(3).Export "C:\Users\Chunk\Reports\Slides\" &"str1_depa.jpg", "JPG"
.Slides(4).Export "C:\Users\Chunk\Reports\Slides\" &"str1_depb.jpg", "JPG"
.Slides(5).Export "C:\Users\Chunk\Reports\Slides\" &"str1_depc.jpg", "JPG"
.Slides(6).Export "C:\Users\Chunk\Reports\Slides\" &"str1_depd.jpg", "JPG"
.Slides(7).Export "C:\Users\Chunk\Reports\Slides\" &"str1_depe.jpg", "JPG"
.Slides(8).Export "C:\Users\Chunk\Reports\Slides\" &"str1_depf.jpg", "JPG"
.Slides(9).Export "C:\Users\Chunk\Reports\Slides\" &"str1_depg.jpg", "JPG"
.Slides(10).Export "C:\Users\Chunk\Reports\Slides\" &"str1_deph.jpg", "JPG"
.Slides(11).Export "C:\Users\Chunk\Reports\Slides\" &"str1_depi.jpg", "JPG"
.Slides(12).Export "C:\Users\Chunk\Reports\Slides\" &"str1_depk.jpg", "JPG"
.Slides(13).Export "C:\Users\Chunk\Reports\Slides\" &"str1_depl.jpg", "JPG"
.Slides(14).Export "C:\Users\Chunk\Reports\Slides\" &"str1_depm.jpg", "JPG"
.Slides(15).Export "C:\Users\Chunk\Reports\Slides\" &"str1_depn.jpg", "JPG"
.Slides(16).Export"C:\Users\Chunk\Reports\Slides\" & "str1_depo.jpg","JPG"
.Slides(17).Export "C:\Users\Chunk\Reports\Slides\" &"str1_depp.jpg", "JPG"
.Slides(18).Export "C:\Users\Chunk\Reports\Slides\" &"str1_ttl.jpg", "JPG"
End With
'closes powerpoint
pptPres.Close
Set pptPres =Nothing
pptApp.Quit
Set pptApp =Nothing
'Open Worddocument and import graphs
Set wrdApp =CreateObject("Word.Application")
wrdApp.Visible =True
Set wrdFile =wrdApp.Documents.Open("C:\Users\Chunk\Reports\Store1_Weekly_Report.docm")
With wrdFile
.Image1.Picture =LoadPicture("C:\Users\Chunk\Reports\Slides\tot_prod.jpg")
End With
End Sub
Any help/direction you can give is greatly appreciated.
Sincerely,
Chunk