Solved

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

Posted on 2013-02-01
2
1,631 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

696 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