Solved

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

Posted on 2013-02-01
2
1,564 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
ID: 38845386
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
ID: 38845791
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
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…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

910 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

23 Experts available now in Live!

Get 1:1 Help Now