If you need assistance with your code, or you are looking for a VBA programmer to hire feel free to contact me. Word VBA, Picture Format CropBottom, CropLeft, CropRight and CropTop.
How to resize excel vba code#
You can download the file and code related to this article from the link below: The rest of the code is pretty much the same as the previous section. This will prevent the picture height from resizing when the width is resized. To test out your new button, click inside cell A1 just to highlight your starting. Change the text of the button to Range Resize. When the Assign Macro dialogue box appears, select your RangeResize Sub from the list. The highlighted text sets the LockAspectRatio to false. Your code will then look like this: Go back to your spreadsheet and add a new button. = lngPercent2Scale * lngScaledWidth / lngOriginalWidth InlineShapes.Item(1).LockAspectRatio = msoFalseĪ(1).WidthĪ(1).ScaleWidth = _ The rest of the code is similar to the previous section. The code below automates a new word document, copies the image and pastes it in the new document: In this method the following algorithm is used:Ī(1).HeightĪ(1).ScaleHeight = _ A better method would be to copy the picture to a new document and rescale it there. This resizing might mess up your word document. It is the fact that the image is actually resized to its original size to gets its original height . Note: There is one problem with this method. The line below resizes the image back to the initial height: The code below resizes the picture to its original size and gets the height of the original picture: = lngPercent2Scale * lngScaledHeight / lngOriginalHeight LngScaledHeight / lngOriginalHeight * 100 LngOriginalHeight = InlineShapes.Item(1).Height LngScaledHeight = InlineShapes.Item(1).Height
How to resize excel vba full#
In the figure below you can see the image in its full scale: The picture was rescaled upon inserting into the document. The reason for this is because the original picture size is almost twice the size of the current picture. Upon running the code below we would expect the height of the image to be reduced by 30 percent, but instead the image becomes longer in height: Note that if not resized by the user, larger picture are resized by default upon being inserted in the word document.įor example take a look at the figure below: The problem with the code above is that the picture is scaled relative to its original size. The following code resizes the picture width to 40% of the original picture width: The following code resizes the picture height to 90% of the original picture height:
ScaleWidth property of their associated shape container. This property determines the size in percent relative to the original picture size to scale the image.