PDA

View Full Version : Change ActiveX Image Control from UserForm



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

Kenneth Hobs
11-29-2018, 06:47 PM
Open your DOCM and in Developer ribbon item, choose Design mode like you would in Excel. Doubleclick the object. You can then see the control's name.


.img_stores_ttl.Picture = LoadPicture("C:\Users\Chunk\Reports\Slides\tot_prod.jpg")

snb
11-30-2018, 02:47 AM
I haven't got a clue what you are trying to accomplish.

1. You don't need powerpoint to save shapes in Excel as a file
2. You don't need Word to adapt properties of picture files

Chunk
11-30-2018, 05:09 AM
snb,

The short and dirty of it is this,

I'm running a userform, from excel. I want to take the slides from a powerpoint file and insert them into a word document in a specific order.

Chunk

snb
11-30-2018, 06:44 AM
Why Excel ?

You can use a userform in Word or in Powerpoint

Chunk
11-30-2018, 12:03 PM
snb,

I am using excel because I already have a userform built that deals with like data for the report I am producing.

Chunk