|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
How do I change multiple pictures in Word 2016 to all new pictures that appear in a specified order?
How do I get Word 2016 (either through a macro or through some third-party program) to change multiple selected pictures so that they appear in an order that I choose? For example, say I have 50 random pictures (all residing in their own separate cell of a word table). And then say I have 300 more in a folder somewhere. How do I have it so that I first choose which pictures I want (in the order I chose then like pic 40, pic 57, pic 23, pic 158, etc.) and then have the 50 pictures in the document be changed to the 50 new pictures I selected.
Currently, I have to manually select a picture, right-click and pick "change picture", select "from a file", choose which folder the new pictures reside in, then pick the one picture, and press insert. I have to do that for every picture and for my job that can be over 400 pictures! You can see a portion of what the layout looks like in the attachment that I added. As you can see, I have the picture in one cell with a caption underneath and then blank space in the cell to the right (this is where I write other stuff). This repeats for however many rows and there are anywhere from 8 to 12 separate word tables in the document that look exactly like this. Is there a macro or add-on that can do this? I'm not saying it has to do exactly what I said, but something close. Like maybe a macro that inserts new pictures in the specified order but inserts then in the same places or something. I couldn't find any third-party way of doing this so any recommendations will help. One limitation is that I can't rename the pics so that they show up in the order I want as that would take nearly as long as before. Unless there's a program that can do that separately. If there is one that can order them, then it could be that a macro or something inserts the pictures in order. All I would have to then is form a table around all the pictures (I think). Forgive me for the complexity of this problem and thank you guys for the help. Last edited by chaz; 07-05-2018 at 10:43 PM. |
#2
|
||||
|
||||
I don't see an attachment.
The concept is achievable and the interface to allow you to select an order could be done a few different ways: vba userform; multi-select file chooser; input list of filenames in table/excel/etc. You might also need to start replacing the pictures from a particular point unless you are really sure about the completeness and correctness of the chosen order.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
Sorry about that. Its added now.
I'm honestly not entirely sure what most of those things are, but I appreciate the feedback. I'm no programmer, but I'm willing to learn if this problem is not considered advanced. Also I can promise that the order is pretty set in stone. All I ever do is maybe delete a picture or two out of the set. |
#4
|
||||
|
||||
Try this code - the macro is called ReplaceImages. It is written to run from the current selection point to the end of the document and continuously open the usual dialog until it runs out of pictures in the document.
It doesn't include a method of breaking the code if choose to stop before reaching the end of the document. The logical way to do that would be to detect if a dialog was dismissed by pressing Cancel but I'm not sure how I would do that. Someone else might have a good idea on how to do that. Code:
Sub ReplaceImages() Dim i As Integer, aRng As Range Set aRng = Selection.Range aRng.End = ActiveDocument.Range.End For i = 1 To aRng.InlineShapes.Count aRng.InlineShapes(i).Select funReplaceInlineShape aRng.InlineShapes(i) Next i End Sub Function funReplaceInlineShape(origShp As InlineShape) As Boolean Select Case origShp.Type Case msoAutoShape, msoFreeform, 6 'this is a shape with a picture fill CommandBars.ExecuteMso ("ObjectPictureFill") Case wdInlineShapePicture 'this is a picture placed into the doc If CInt(Application.Version) < 16 Then 'following only works pre Word 2016+ CommandBars.ExecuteMso ("PictureChange") Else 'following is for Word 2016+ CommandBars.ExecuteMso ("PictureChangeFromFile") End If End Select End Function
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
||||
|
||||
As there is nothing particularly significant about the document - it's a table with pictures. Why not simply create a new table with the pictures you want, in the order you want them - see http://www.gmayor.com/photo_gallery_template.html
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#6
|
|||
|
|||
It worked Guessed. Thank you
Hey guessed I was able to get your code to work. This has made my work far easier allowing me to delegate more time to the rest of the report. I'll try to see if I can figure out how to get the macro to cancel without waiting for it to finish, but for now I am more than pleased.
|
#7
|
||||
|
||||
If you are using the code and the workflow is efficient enough, then it is worthwhile to come up with a solution to how the code can be prematurely terminated. Ctrl-Break would be one way but it isn't particularly elegant.
Another way would be to add a prompt for "Would you like to do another one?" but that would be an extra click which would prove more of an annoyance. Another way would be to ask up front how many graphics you want to do or maybe limit the counter to blocks of 10?
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#8
|
||||
|
||||
Yep, I had a play with it and Ctrl-Break is adequate if it is only you running it.
If you had a bunch of people using the macro then it would be worth finding a more elegant way to break the code but a single user can be trained to use the regular code interruption method.
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
Tags |
macro help, word 2016-64, word table |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Pictures within doc print way too small: word 2016 | pamaples | Word | 4 | 08-27-2018 03:02 PM |
Text prints OK, pictures print way too small: Word 2016 doc | pamaples | Drawing and Graphics | 0 | 04-27-2017 09:14 AM |
Word 2016 Not Auto Aligning Pictures to Text | CrossReach | Word | 2 | 01-21-2017 08:14 AM |
Word 2013 - pictures inserted into word appear in two different formats, need to change | katm3 | Word | 4 | 05-22-2015 12:53 AM |
Resize multiple pictures in a Word 2010 table | JBA479 | Word VBA | 1 | 01-24-2014 08:51 PM |