Solved

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

Posted on 2013-02-01
2
1,668 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This article describes a serious pitfall that can happen when deleting shapes using VBA.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

724 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