Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 545185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:44:05+00:00 2026-05-13T10:44:05+00:00

how do i programatically add an image using VBA to a word document. I’ve

  • 0

how do i programatically add an image using VBA to a word document.

I’ve tried adding a bookmark to the word document and tried adding the image, but it always adds to the top of the form rather than the bookmark area. Should i persevere with the bookmark or is there another way to add the image?

See my code below:

Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Set wrdApp = CreateObject("Word.Application")

Dim objWdRange As Word.Range
Dim GraphImage As String
Dim shortString As String 

shortString = Range("short").Value

GraphImage = "http://xxx.xxxxx.com/xxx/xxx.png?instrument=Image.png"

wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Open("C:\Program Files\My Dropbox\dailystrategy.doc")

Set objWdRange = wrdDoc.Content

With wrdDoc


    If wrdDoc.Bookmarks.Exists("shortString ") Then
        wrdDoc.Bookmarks("shortString ").Range.Text = shortString 
    End If      

     If wrdDoc.Bookmarks.Exists("GraphImage") Then
        wrdDoc.Bookmarks("GraphImage").Range.InlineShapes.AddPicture Filename:=GraphImage, LinkToFile:=False, SaveWithDocument:=True
     End If


    wrdDoc.SaveAs "c:\temp\test.doc"

  ' close the document
    Set wrdDoc = Nothing
    Set wrdApp = Nothing
End With

regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:44:05+00:00Added an answer on May 13, 2026 at 10:44 am

    Well, first we need to clean up your code a bit, like below. This runs fine on my site – it places the image right at the front of the GraphicImage bookmark, not at the top of the document – but maybe your image is so large it extends to the top?

    Dim objWdRange As Word.Range
    Dim GraphImage As String
    Dim shortString As String
    shortString = Range("short").Value '? don't know what this is for
    GraphImage = "http://xxx.xxxxx.com/xxx/xxx.png?instrument=Image.png"
    wrdApp.Visible = True
        Set wrdDoc = wrdApp.Documents.Open("C:\Program Files\My Dropbox\dailystrategy.doc")
        Set objWdRange = wrdDoc.Content '? don't know what this is for
        With wrdDoc
            If .Bookmarks.Exists("shortString ") Then
               .Bookmarks("shortString ").Range.Text = shortString
            End If
         If .Bookmarks.Exists("GraphImage") Then
             Dim wrdPic As Word.InlineShape
             Set wrdPic = .Bookmarks("GraphImage").Range.InlineShapes.AddPicture(FileName:=GraphImage, LinkToFile:=False, SaveWithDocument:=True)
             wrdPic.ScaleHeight = 50
             wrdPic.ScaleWidth = 50
         End If
           .SaveAs "c:\temp\test.doc"
        End With
        wrdDoc.Close
        Set wrdDoc = Nothing
        wrdApp.Quit
        Set wrdApp = Nothing
    

    EDIT: Jan 11, 2010
    The above code was changed to include

     If .Bookmarks.Exists("GraphImage") Then
     Dim wrdPic As Word.InlineShape
     Set wrdPic = .Bookmarks("GraphImage").Range.InlineShapes.AddPicture(FileName:=GraphImage, LinkToFile:=False, SaveWithDocument:=True)
        wrdPic.ScaleHeight = 50
        wrdPic.ScaleWidth = 50
     End If
    

    This sets the picture as an object and then uses the scaling methods ScaleHeight and ScaleWidth to make it 50% smaller in both height and width.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 284k
  • Answers 284k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer C strings are 0-terminated. This means that if you want… May 13, 2026 at 4:24 pm
  • Editorial Team
    Editorial Team added an answer Yes, the constant CI_VERSION will give you the current CodeIgniter… May 13, 2026 at 4:24 pm
  • Editorial Team
    Editorial Team added an answer The fact that the web page points out that: The… May 13, 2026 at 4:24 pm

Related Questions

OK, I feel dumb asking this, but I've spent the whole afternoon trying to
I'm trying to create an application that uses the iPhone MapView (under Google Code).
We have an asp.NET page which is programmaticaly adding data as new list items
I need help programatically graphing more points than can fit in a single Excel
i have a pretty simple rectangluar WinForm that uses timers to check the end

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.