Solved

Word 2010 VBA: How to import image and resize height and width with VBA?

Posted on 2013-02-01
2
1,545 Views
Last Modified: 2013-02-02
How do I use VBA to import an image into Word 2010 then rezise the height and width so that the image does not push the other page elements out of place?

Word 2010
Access 2010

Note: the process of creating the Word files runs through a loop in an Access module. Currently, I use Access to copy and replace bookmarked fields in the Word document. However, it is possible that an image may not exist for the document I am creating so I would like that the Word document is still generated even if the image is missing.

Thank you
0
Comment
Question by:CafeTica
  • 2
2 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
The image can be added as an inline shape or a 'floating' shape.  An inline shape takes a position as a large character in the text.

The way that text is arranged around a 'floating' shape depends on its wrap setting. Without seeing the document, the only way to be certain that the text is not disturbed is for the shape's wrap setting to be behind or in front of the text.
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
Comment Utility
Here is some code to get you started:
Sub AddInLine(doc As Word.Document, strFileName As String, strBookMark As String)
    Dim ilsh As Word.InlineShape
    
    Set ilsh = doc.InlineShapes.AddPicture(strFileName, , True, doc.Bookmarks(strBookMark).Range)
    ilsh.Height = CentimetersToPoints(3)
    ilsh.Width = CentimetersToPoints(4)
End Sub

Sub AddShape(doc As Word.Document, strFileName As String, strBookMark As String)
    Dim sh As Word.Shape
    
    Set sh = doc.Shapes.AddPicture(strFileName, , True, , , , , doc.Bookmarks(strBookMark).Range)
    sh.Top = CentimetersToPoints(1)
    sh.Left = CentimetersToPoints(2)
    sh.Height = CentimetersToPoints(3)
    sh.Width = CentimetersToPoints(4)
End Sub

Open in new window

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now