Inline ScaleHeight/ScaleWidth Returns o In Word 2007

G

George Lee

We (finally) upgraded to Office 2007 and some macros that had been running in
Word 2003 for months have stopped. The problem is that the
inlineshape.ScaleHeight and inlineshape.ScaleWidth properties now always
return zero (0). In Googling the answer, some had posted this very question
but there has never been a good reply. Does anyone know what this might
return zero (0)?

The code may not be useful:
Dim myGraphic As Word.InlineShape
Set myGraphic = gTargetDoc.InlineShapes.AddPicture(fileName:=myFileName,
Range:=gTargetDoc.Windows(1).Selection.Range)

In this case, myGraphic.Height=468, myGraphic.Width=605 but
myGraphic.ScaleHeight=0 and myGraphic.ScaleWidth=0.
 
D

Doug Robbins - Word MVP on news.microsoft.com

Running the following code in Word 2007 displays "Scale Height is 100; Scale
Width is 100" in the message box for me.

Dim myGraphic As Word.InlineShape
Set myGraphic =
ActiveDocument.InlineShapes.AddPicture(FileName:="c:\logo.jpg", _
Range:=ActiveDocument.Windows(1).Selection.Range)
MsgBox "Scale Height is " & myGraphic.ScaleHeight & "; Scale Width is " &
myGraphic.ScaleWidth


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
G

George Lee

I’ll pass this off as a bug. The code works correctly as a macro. The problem
starts when it’s part of a VB application. The values are zero. You can read
them as zero, you can’t manually set them to anything other than zero, but
the image is still properly scaled.
 
M

marc.wiener

I’ll pass this off as a bug. The code works correctly as a macro. The problem
starts when it’s part of a VB application. The values are zero. You canread
them as zero, you can’t manually set them to anything other than zero, but
the image is still properly scaled.

:







- Show quoted text -

I have VBA macro validation code on figures that uses Scale Height and
Width that is also returning 0:

If Round(currFig.ScaleHeight) <> 100 Or Round(currFig.ScaleWidth) <>
100 Then...

If this is a bug are there any workarounds to know that the figure is
not 100%?

Marc
 
Joined
Aug 20, 2020
Messages
1
Reaction score
0
Looks like this and similar queries have been dormant since around 2009, but I have run into this bug while trying to find the original size of images in Word 2010 (and later).

What the original poster here and in other similar reports failed to explain/realize is that the bug is only manifest in DOC files - if you try to query InlineShape.ScaleHeight or .ScaleWidth in a DOC file in Word 2007+, it always returns 0, regardless of the actual scaling.

If you record a macro while you change the scaling of an InlineShape in a DOC file, the properties that are recorded as changing are the .Height and .Width, rather than the .ScaleHeight and .ScaleWidth, despite the fact that it is the Scale: Height and Width fields on the Format Picture dialog that have been modified. Similarly, if you hit the Reset button to change the Scale: Height and Width to 100%, the properties that are recorded as changing are the .Height and .Width.

I need to find the true size of an InlineShape, regardless of whether the Word file is in DOC or DOCX format - I can't resave DOC as DOCX to avoid the bug.

If anyone is still monitoring this thread, my question is, how does Word 2007+ know what the true size of the InlineShape is in a DOC file, since the .ScaleHeight and .ScaleWidth properties are broken? I can't see any other properties accessible in VBA that would allow the true size to be calculated, but Word must have access to this information, since it (correctly) displays the scaling in the Format Picture dialog.
 
Last edited:
Joined
Sep 5, 2021
Messages
2
Reaction score
0
I too am struggling to compress. I need to go to 150ppi or 95ppi, I have managed to force embedded customer photos in Outlook Email body saved to docx in a slipstick.com macro - to fit within the A4 margins as per below. I am struggling to do compress, I think I have done a try of scale height and width, I will try again. Compression is the last macro in a suite of Macros for colleagues.
Other Outlook Macros from www.slipstick.com are to save to text file, and to save all attachments to a folder, which is killed before each running.

Other Word Macros as well as the one below are Rotate all or a selection of images via a UserForm (help from gregmaxey) and his Section break and reconnect breaks macros.

Sub ResizePicturesIF()
'Macro S
Dim oDoc As Document, oShape As InlineShape
Set oDoc = Application.ActiveDocument
For Each oShape In oDoc.InlineShapes
If oShape.Width > 510 Then
oShape.LockAspectRatio = True
oShape.Width = 510
End If
If oShape.Height > 660 Then
oShape.LockAspectRatio = True
oShape.Height = 660
End If
Next
Set oDoc = Nothing
End Sub
 

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