MS_Word vba: Placing a .jpg graphic at specific positions in text; all appended automatically

I have a multi-step process in Excel that needs to be reported to a Word file.
Each step has a characteristic graphic icon, which is to be followed by text reporting parameters for that  step.
The data and graphic details are read from arrays sequentially, so I think the Word doc should grow by appendation.

So the layout would be:
Step A Graphic (say 40x40 in size)
       Step A parameters .....

Step B Graphic (say 40x40 in size)
       Step B parameters .....

etc.

Though I will need to use Excel in early binding with MW Word to create the Word report, at present I'm concentrating on using Word vba ALONE to place graphics in a word file, and I'm finding difficulties.

For Text, I'm using FileSystemObject.TextStream.Write with vba in excel and writing to a doc file:

Sub appendRecordReport_txt()
    Dim fso As New FileSystemObject
    Dim stream As TextStream

    Set stream = fso.OpenTextFile("c:\tstTextFiles\testfile.doc", 8, TristateFalse) 'where 8 = ForAppending ...
    stream.Write "This line uses the Write method nov20."                      '.... and appends this text
    stream.Close
End Sub

For Graphic, (using vba in word right now) I have got the following, which I've run after simply clicking the word page to which the graphic is to be sent:
       Dim shp As Shape
       With ActiveDocument
              Set shp = ActiveDocument.Shapes.AddPicture(fileName, msoFalse, msoTrue)
       end with

However, though i have code to size, crop, and position the graphic, I these parameters interact and make it difficult to work out how they work, or even whether I've selected the right starting points:
             shp.Top
             shp.Left
             .PictureOffsetX = 15 'picWidth / 10
             .PictureOffsetY = 16 'picHeight / 10
            .PictureHeight = picHeight * 0.5
            .PictureWidth = picWidth * 0.5
           
            ' Now modify the cropping by changing the shape of the container. Changing the shape alters
            ' the portion of the picture that you see:
            .ShapeHeight = 140
            .ShapeWidth = 140
            .ShapeLeft = 110
            .ShapeTop = 120  

(sourced from: https://code.msdn.microsoft.com/office/Word-2010-Add-Picture-ddb5c728)

My first Question is: Have I selected the right methods for text and graphic, and can you help me with the principles of placing graphics (sized) at the right point in text?  Issues such as text margins and font size can follow later.

I hope you can help me!

Thanks
Kelvin
Kelvin4Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GrahamSkanRetiredCommented:
Personally, I don't know how well FSO can interpret Word objects and methods, so I stick to coding from the Word object library.

You should be aware that pictures can be represented in Word as two entirely different objects and processes, though the Word GUI somewhat blurs that. In terms of the coding, pictures and other graphical objects can be considered as Shape or as InLineShape objects. In the latter, pictures, and other graphical objects are treated as if they were characters (albeit probably big) with a fixed position in the text, which might be what you need here

Shape objects, on the other hand are merely 'anchored' to a particular text paragraph. In the Word application interface they can be dragged about, though their final position in any printout is subject to particular rules that can depend on the outcome of pagination. The 'wrapping' setting determines how the text reacts to the presence of the shape.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kelvin4Author Commented:
GrahamSkan, that got me started..
At this source: http://technet.microsoft.com/en-us/library/ee692911.aspx , which seems to follow your advice.
After replacing   objSelection.TypeParagraph() with   objSelection.TypeParagraph, and adding SaveAs,

The resultant code worked for me, thanks!

Sub inLine1()
    Dim wrdApp As Word.Application
    Dim objDoc As Word.Document
    Dim objShape As Word.InlineShape
    Dim objSelection As Word.Selection
   
    Set wrdApp = CreateObject("Word.Application")
    wrdApp.Visible = True
   
    Set objDoc = wrdApp.Documents.Add()

    Set objSelection = wrdApp.Selection

    objSelection.TypeText "Here is a sentence preceding the picture."
    objSelection.TypeParagraph

    'Set objShape = objSelection.InlineShapes.AddPicture("D:\aaThink_Build\Thk_Building\xlImages\cross.jpg")
    Set objShape = objSelection.InlineShapes.AddPicture("D:\aaThink_Build\Thk_Building\xlImages\openVisio.jpg")
    objShape.Height = 50
    objShape.Width = 50
    objSelection.TypeParagraph
    objSelection.TypeText "Here is a sentence following the picture."
    objSelection.TypeParagraph
   
    objDoc.SaveAs ("C:\tstTextFiles\myFile inLine in folder")
   
End Sub
0
Kelvin4Author Commented:
Thanks for very rapid guidance that helped me get started.
Kelvin
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Word

From novice to tech pro — start learning today.