Need Help for positioning image/images in a vbscript code while creating a word document RRS feed

  • Question

  • Hi,

    Here is the follwoing code I have used to insert an image in a header of a word document:

    With objDoc.Sections(1)
            '.Headers(wdHeaderFooterPrimary).Range.Text = "Text as Header"
            .Headers(wdHeaderFooterPrimary).Shapes.AddPicture "P:\exports\5780\Doc\fineline.jpg"
            .Headers(wdHeaderFooterPrimary).shapes.Item(1).height = 55
            .Headers(wdHeaderFooterPrimary).Shapes.Item(1).width  = 150
    End With

    The problem is I cannot change the position of the image anyway. I have tried teh following code.

    Set objSelection = objWord.Selection

    objSelection.ShapeRange.WrapFormat.Type = 3
    objSelection.ShapeRange.ZOrder 5
    objSelection.ShapeRange.Left = wdShapeCenter

    But getting an error of

    " The Left method or property is not available because the drawing operation cannot be applied to the current selection."

    I am stuck. I need help right way. Thanks much for helping ...

    Friday, September 27, 2013 6:41 PM

All replies

  • You should be able to use code like this:

        Dim shp
        With objDoc.Sections(1).Headers(wdHeaderFooterPrimary)
            .Range.Text = "Text as Header"
            Set shp = .Shapes.AddPicture("P:\exports\5780\Doc\fineline.jpg")
            With shp
                .Height = 55
                .Width = 150
                .Top = 30
                .Left = 50
            End With
        End With

    Regards, Hans Vogelaar (

    Friday, September 27, 2013 8:19 PM
  • Hi

    Thanks so much. That worked like a charm.

    I need more help though. I am new in using Word Object in VB. I am trying to built a table that has some style like below:

    1) the table should have grid in all columns and row -- I guess I should use  autoformat 16 ,.....

    2) first row should have a black background and white font -- I know the code for white font but no where I found what should be the code for black backgorund for the first row. When you access Cell(x,1) it does not have a property for setting the background color for that cell.

    3) also, I am using the following code to resize the height of the table. but it is not working

    .AutoFormat 35, True, True, True, True, True, False, True, False, True 
     .Rows(1).Height = 7

    I have a deadline of end of day tomorrow so any help would be very much appreciated.

    Thanks much in advance

    Tuesday, October 1, 2013 1:58 PM
  • I'm very sorry, I was away for several days, so I couldn't reply in time for your deadline.

    Here is some sample code:

    Sub CreateTable()
        With ActiveDocument.Tables.Add(Range:=Selection.Range, NumRows:=3, NumColumns:=3)
            .Style = "Table Grid"
            .Rows(1).Cells.Shading.BackgroundPatternColor = wdColorBlack
            .Rows(1).Range.Font.ColorIndex = wdWhite
            .Rows.HeightRule = wdRowHeightAtLeast
            .Rows.Height = InchesToPoints(0.4)
        End With
    End Sub

    Regards, Hans Vogelaar (

    Friday, October 4, 2013 9:35 PM