Create a macro to resize images?
Solved
Rdom85
Posted messages
6
Status
Membre
-
Adakh -
Adakh -
Hello,
I would like to create a macro in Word 2007 to resize images already inserted in the text.
The macro should set the image with the following data:
Height: 6cm (while keeping the proportions)
Wrapping: behind the text.
Thank you for your help
Configuration: Windows 7
I would like to create a macro in Word 2007 to resize images already inserted in the text.
The macro should set the image with the following data:
Height: 6cm (while keeping the proportions)
Wrapping: behind the text.
Thank you for your help
Configuration: Windows 7
10 réponses
Hello,
The fact that they come out of the camera is not the issue.
For now, I still don't know if they have a casing...
So, let's assume there are images without casing, in which case, we'll start by converting them, then resizing them and placing them behind the text.
--
If you want to be helped effectively, make sure you are on the right forum,... and specify the software you're using as well as its version. We lack clairvoyants!
The fact that they come out of the camera is not the issue.
For now, I still don't know if they have a casing...
So, let's assume there are images without casing, in which case, we'll start by converting them, then resizing them and placing them behind the text.
Sub images() Dim image As InlineShape Dim image2 As Shape For Each image In ActiveDocument.InlineShapes image.ConvertToShape Next For Each image2 In ActiveDocument.Shapes image2.Height = CentimetersToPoints(6) image2.WrapFormat.Type = wdWrapBehind Next End Sub
--
If you want to be helped effectively, make sure you are on the right forum,... and specify the software you're using as well as its version. We lack clairvoyants!
Try this macro that will work after selecting an image:
As a point of reference, there is no way to compress images via VBA. Or at least very complicated workarounds that would involve exporting images, compressing them, and re-importing...
In reality, compression is automatic in versions 2007/2010. Otherwise, you just need to click once in the Compress dialog to compress all images at once.
In any case, I recommend using Microsoft Office Picture Manager to retrieve all these photos, compress them at once, and copy them to a new folder to avoid damaging the originals. It's very quick and much more efficient in terms of compression than Word.
m@rina
--
If you want to be helped effectively, make sure you're on the right forum,... and specify the software used as well as its version. We lack clairvoyants!
Sub image() On Error Resume Next Selection.InlineShapes(1).ConvertToShape On Error GoTo erreur With Selection.ShapeRange .Height = CentimetersToPoints(6) .WrapFormat.Type = wdWrapBehind End With Exit Sub erreur: MsgBox "the selection does not contain an image" End Sub
As a point of reference, there is no way to compress images via VBA. Or at least very complicated workarounds that would involve exporting images, compressing them, and re-importing...
In reality, compression is automatic in versions 2007/2010. Otherwise, you just need to click once in the Compress dialog to compress all images at once.
In any case, I recommend using Microsoft Office Picture Manager to retrieve all these photos, compress them at once, and copy them to a new folder to avoid damaging the originals. It's very quick and much more efficient in terms of compression than Word.
m@rina
--
If you want to be helped effectively, make sure you're on the right forum,... and specify the software used as well as its version. We lack clairvoyants!
Hello,
Do your images have a formatting (SHAPE) or not (INLINESHAPE)?
m@rina
--
If you want to be helped effectively, make sure you are in the right forum,... and specify the software used as well as its version. We lack clairvoyants!
Do your images have a formatting (SHAPE) or not (INLINESHAPE)?
m@rina
--
If you want to be helped effectively, make sure you are in the right forum,... and specify the software used as well as its version. We lack clairvoyants!
Hello M@rina,
To begin with, thank you for your attention.
My images are straight out of the camera, so no work has been done on them.
After that, they should be: image behind the text.
Dominique
To begin with, thank you for your attention.
My images are straight out of the camera, so no work has been done on them.
After that, they should be: image behind the text.
Dominique
Hello M@rina,
Great !!!!! It meets the needs with a few details to note:
- I would like the macro to apply only to the selected photo in the document without modifying the other photos
- it should also be compressed to 150dpi.
I assume that when I need to compress them to 96dpi, I just need to change the number (150 to 96) in the command line to create another macro.
Dominique
Great !!!!! It meets the needs with a few details to note:
- I would like the macro to apply only to the selected photo in the document without modifying the other photos
- it should also be compressed to 150dpi.
I assume that when I need to compress them to 96dpi, I just need to change the number (150 to 96) in the command line to create another macro.
Dominique
Good evening,
To simplify, I would still like to know if the initial image has a wrapping or not...
m@rina
--
If you want to be helped effectively, make sure you are on the right forum,... and specify the software used as well as its version. We lack fortune tellers!
To simplify, I would still like to know if the initial image has a wrapping or not...
m@rina
--
If you want to be helped effectively, make sure you are on the right forum,... and specify the software used as well as its version. We lack fortune tellers!
Hello M@rina,
That's perfect. Your macro works wonderfully, your advice is clear, concise, and quick as well.
Without wanting to steal your thunder, do you have any advice for me to get started with the command lines of Word-Excel macros?
In version 97, it was easy to have an intuitive learning approach; you just had to record a macro and look at the command lines automatically created by Word-Excel.
With version 2007, this learning method doesn't work in many cases, such as with image macros.
It seems that some knowledge of VB is necessary; do you have any advice?
Thanks again for your invaluable help.
Dominique
That's perfect. Your macro works wonderfully, your advice is clear, concise, and quick as well.
Without wanting to steal your thunder, do you have any advice for me to get started with the command lines of Word-Excel macros?
In version 97, it was easy to have an intuitive learning approach; you just had to record a macro and look at the command lines automatically created by Word-Excel.
With version 2007, this learning method doesn't work in many cases, such as with image macros.
It seems that some knowledge of VB is necessary; do you have any advice?
Thanks again for your invaluable help.
Dominique
Hello,
It is true that with the new versions, macro recording works less well. In fact, it has been removed for PowerPoint, which may seem annoying, but it didn't really serve much purpose, as it was so poor. Often the recordings were empty!
I would say that it's by recording macros that one becomes a macro writer!! ;))
I have an article on my site called the A B C of VBA that you can check out:
https://faqword.com/index.php/word/tutos/toutes-versions/615-le-b-a-ba-du-vba
and particularly the last chapter "What are the basic concepts".
Once you've understood what an object, a property, a method, a variable, etc. are, you need to start. Beginning with simple things, then moving to more advanced ones.
You should also consult websites where you can find many examples. On my site, which specializes in Word and PowerPoint, you'll find quite a few macro examples for these two applications. For Excel, there are so many that I'm having a hard time citing one. I can still mention the site for Excel enthusiasts: http://excelabo.net/ where you'll find lots of codes and workbooks to download.
However, I think a book is also welcome. I recommend this one that talks about macros for all Office applications:
https://www.amazon.fr/VBA-pour-Office-2007-applications/dp/2742982450/ref=cm_cr_pr_pb_t
co-written by Geo who, like me, is a Microsoft MVP, and is also the author of the site excelabo.net.
m@rina
--
If you want to get effective help, make sure you are on the right forum,... and specify the software used as well as its version. We lack fortune tellers!
It is true that with the new versions, macro recording works less well. In fact, it has been removed for PowerPoint, which may seem annoying, but it didn't really serve much purpose, as it was so poor. Often the recordings were empty!
I would say that it's by recording macros that one becomes a macro writer!! ;))
I have an article on my site called the A B C of VBA that you can check out:
https://faqword.com/index.php/word/tutos/toutes-versions/615-le-b-a-ba-du-vba
and particularly the last chapter "What are the basic concepts".
Once you've understood what an object, a property, a method, a variable, etc. are, you need to start. Beginning with simple things, then moving to more advanced ones.
You should also consult websites where you can find many examples. On my site, which specializes in Word and PowerPoint, you'll find quite a few macro examples for these two applications. For Excel, there are so many that I'm having a hard time citing one. I can still mention the site for Excel enthusiasts: http://excelabo.net/ where you'll find lots of codes and workbooks to download.
However, I think a book is also welcome. I recommend this one that talks about macros for all Office applications:
https://www.amazon.fr/VBA-pour-Office-2007-applications/dp/2742982450/ref=cm_cr_pr_pb_t
co-written by Geo who, like me, is a Microsoft MVP, and is also the author of the site excelabo.net.
m@rina
--
If you want to get effective help, make sure you are on the right forum,... and specify the software used as well as its version. We lack fortune tellers!