converting pictures to right size

B

BorisS

any way I can have all pictures in a document (will be pasted charts from
another app) converted to a particular height/width?

Thx.
 
K

Klaus Linke

BorisS said:
any way I can have all pictures in a document (will be pasted
charts from another app) converted to a particular height/width?


Hi Boris,

You'll probably want to keep the proportions... So you'll have to decide
whether they should all get the same heigh, or the same width.

Say if you decide on "same width", and the pics are inline, something like:

Dim myIS As InlineShape
Dim myScale As Double
For Each myIS In ActiveDocument.InlineShapes
myScale = myIS.Height / myIS.Width
myIS.Width = myFixedWidth
myIS.Height = myIS.Width * myScale
Next myIS

Regards,
Klaus
 
B

BorisS

Klaus, regards. Just so I educate myself a bit, what are considered
InlineShapes? Is that specific to shapes in tables, or any pictures? Also,
I noticed the use of myFixedWidth. That's defined, or its native to the app?
Just asking because you seemed to define the other "my" terms.

Any chance there's some sort of statement that can be put in which will ask
the question "next?" and give an Ok or Cancel, after each of the instances?
I don't know if I'll use it, but having it and being able to comment it if
not needed would be nice.

Finally, how does the procedure know which actual number to use, or is that
partially what's missing with the myFixedWidth? Can it be set in a way where
the first shape, which I will set manually, will have the width and
dimensions, and then the procedure can take that shape's width (to follow
your suggestion of picking one dimension) and use it as the number for
others? This would avoid having to go into the macro and manually entering
the width.

Thx for any further help.
 
K

Klaus Linke

BorisS said:
Klaus, regards. Just so I educate myself a bit, what are considered
InlineShapes?
Is that specific to shapes in tables, or any pictures?

InlineShapes are in the text flow (as opposed to the Shapes collection,
which live in the drawing layer).

Also, I noticed the use of myFixedWidth.
That's defined, or its native to the app?
Just asking because you seemed to define the other "my" terms.

Just forgot to Dim and set it to some value in the sample: It's the default
width you want (in points).

Dim myFixedWidth as Double
myFixedWidth=100
Any chance there's some sort of statement that can be put in which
will ask the question "next?" and give an Ok or Cancel, after each
of the instances?
I don't know if I'll use it, but having it and being able to comment it if
not needed would be nice.

Sure:

For Each myIS In ActiveDocument.InlineShapes
myIS.Select
Select Case MsgBox("Scale?", vbQuestion + vbYesNoCancel)
Case vbYes
myScale = myIS.Height / myIS.Width
myIS.Width = myFixedWidth
myIS.Height = myIS.Width * myScale
Case vbNo
' do nothing
Case vbCancel
Exit Sub
End Select
Next myIS


Finally, how does the procedure know which actual number to use,
or is that partially what's missing with the myFixedWidth?

See above...
Can it be set in a way where the first shape, which I will set manually,
will have the width and dimensions, and then the procedure can take
that shape's width (to follow your suggestion of picking one dimension)
and use it as the number for others? This would avoid having to go
into the macro and manually entering the width.

You could set myFixedWidth to the width of the first InlineShape at the
start:

myFixedWidth = ActiveDocument.Content.InlineShapes(1).Width

Maybe this would work, too:

myFixedWidth=ActiveDocument.InlineShapes(1).Width

But I'm not sure the InlineShapes are always indexed in the order they
appear in the document.
ActiveDocument.Content.InlineShapes(1) should really pick up the first
InlineShape in the order they appear in the Content (Range).

Greetings,
Klaus
 
B

BorisS

Klaus, thanks so much. I wonder, is there any short list of types of message
boxes that are available in VB? In other words, if I didn't want just a
yes/no, but wanted to give a few options, and then do cases based on those,
how would that look? Or in general, what's my flexibility with them?

The code works flawlessly, by the way. Thanks. I added a second,
preliminary msgbox to ask if the user wanted to go one by one, and with a no
there, I did the first code you wrote (just going through them all, without
asking next.

Thanks again.
 
J

Jonathan West

BorisS said:
Klaus, thanks so much. I wonder, is there any short list of types of
message
boxes that are available in VB? In other words, if I didn't want just a
yes/no, but wanted to give a few options, and then do cases based on
those,
how would that look? Or in general, what's my flexibility with them?

The code works flawlessly, by the way. Thanks. I added a second,
preliminary msgbox to ask if the user wanted to go one by one, and with a
no
there, I did the first code you wrote (just going through them all,
without
asking next.

Thanks again.

Hi Boris,

Look up the MsgBox function in the VBA help to see what variations there
are. They key point to look for is the Buttons parameter of the function.

If you need more than what is offered by the message box, then you will need
to write a Userform for yourself. If you aren't familiar with userforms,
this article will help get you started

How to create a Userform
http://www.word.mvps.org/FAQs/Userforms/CreateAUserForm.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top