locked
Insert multiple images on all pages of a Word document RRS feed

  • Question

  • Hi!

    I'm also trying to insert images into a word document programmatically, and despite having coded for a number of years I don't understand the range bit... :-)  What I'm trying to accomplish is to insert one image on the first page of the document, one on the last page, and a third on every page in between - in the lower right hand corner.  It seems all I need here is a way to define the range - can it be done with a 'GoTo', or a 'Find'? Please, oh please, Cindy, show me the light...

     

    /Carl

     

       Dim Newleft, NewTop, CurrentPage, CurrentShape As Integer
        
        NumPages = ActiveDocument.ActiveWindow.Panes(1).Pages.Count
        CurrentShape = 1
     
        For CurrentPage = 1 To NumPages

            Select Case CurrentPage
            Case 1
                Selection.HomeKey Unit:=wdStory
                ActiveDocument.InlineShapes.AddPicture FileName:= _
                    "C:\FirstPage.bmp" _
                    , LinkToFile:=False, SaveWithDocument:=True
            Case NumPages
                ActiveDocument.InlineShapes.AddPicture FileName:= _
                        "C:\LastPage.bmp" _
                        , LinkToFile:=False, SaveWithDocument:=True
            Case Else
                ActiveDocument.InlineShapes.AddPicture FileName:= _
                        "C:\MiddlePage.bmp" _
                        , LinkToFile:=False, SaveWithDocument:=True
            End Select


            ActiveDocument.InlineShapes(1).ConvertToShape
            ActiveDocument.Shapes(CurrentShape).WrapFormat.Type = 3
            CurrentShape = CurrentShape + 1
            
            Newleft = 541 - ActiveDocument.Shapes(CurrentShape).Left
            ActiveDocument.Shapes(CurrentShape).IncrementLeft Newleft
            NewTop = 687 - ActiveDocument.Shapes(CurrentShape).Top
            ActiveDocument.Shapes(CurrentShape).IncrementTop NewTop

        Next CurrentPage

    Wednesday, April 9, 2008 2:20 PM

Answers

  • Hi Carl

     

    I've split this off from the thread where you replied in order to give your message better visibility.

     

    We need to sort out a couple of issues, I think...

     

    1. Version of Word involved

    2. Is the document going to be edited further, after you've inserted these images?

    3. Have you considered using the document Footer?

     

    The content of a document header or footer repeats on every page. Different First Page is easy enough - that's an option in the UI and the object model. Different last page is a bit more challenging - if you really need a SHAPE object, then you'd need to work with section breaks. If you're only using a SHAPE object because you want a (rectangular) text flow around it, then we can work with a textbox or a frame, inserting the image into that.

     

    Further question: would you be doing this only in a certain document (or type of document)? Or would you need this functionality for "any and all" documents a user may be creating?

     

    Wednesday, April 9, 2008 3:41 PM