Link to home
Create AccountLog in
Visual Basic Classic

Visual Basic Classic

--

Questions

--

Followers

Top Experts

Avatar of rbichon
rbichon

Microsoft Word VBA: Compress image after resize
I have inserted an image into a Word document through VBA. After I resize it in VBA, I want to also compact the image so that it truly becomes the size that I have specified. How is this done in VBA? This is my code:

    Dim objWord As Object
    Set objWord = CreateObject("Word.Application")
    Set shpPic = objWord.ActiveDocument.Shapes.AddPicture("C:\test.jpg")
    shpPic.Height = 180

I know that this resizes the height on the page, but Word does not actually consider it to be that size until it is compressed. Please help.

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of Brian MulderBrian Mulder🇳🇱

Hello rbichon,

as far as i know (always willing to learn) this cannot be done from within the program so you first have to resize the pictures before adding them to document, for a way using a picturebox take a look at source: http://www.codeguru.com/forum/archive/index.php/t-27478.html

hope this helps a bit
bruintje

Avatar of rbichonrbichon

ASKER

The way I am doing it works pretty well for scaling the picture (it is actually run in Access VBA). The problem is that sometimes my users have pictures that are 1600 x 1200 at 300 DPI. Scaling doesn't decrease the size of the picture and we end up with 10MB Word documents. Is there another way to resize the image in VBA before it goes into word?

Avatar of Brian MulderBrian Mulder🇳🇱

hello again,

done some research on this but did you save the files to disk first after resizing and then include them into the document?

bruintje

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of rbichonrbichon

ASKER

No, I just inserted an existing image into the document and resized its borders. Is there a way in VBA to resize an image? Then I could save it temporarily somewhere and insert it then. Let me know.

ASKER CERTIFIED SOLUTION
Avatar of Brian MulderBrian Mulder🇳🇱

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of rbichonrbichon

ASKER

Putting images into a form will cause the database to bloat which I can't have. Your second option seems like it might work. I will give it a shot and let you know what happens. Thanks for the resource.

Avatar of rbichonrbichon

ASKER

The second suggestion worked the best. Thanks.

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.

Visual Basic Classic

Visual Basic Classic

--

Questions

--

Followers

Top Experts

Visual Basic is Microsoft’s event-driven programming language and integrated development environment (IDE) for its Component Object Model (COM) programming model. It is relatively easy to learn and use because of its graphical development features and BASIC heritage. It has been replaced with VB.NET, and is very similar to VBA (Visual Basic for Applications), the programming language for the Microsoft Office product line.