View Single Post
 
Old 03-17-2016, 11:18 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

objword is not the activedocument. doc is the active document. What you should have is something like:

Code:
    Dim oTable As Word.Table 'name the table
    Dim oRng As Word.Range 'name a range

    With objWord
        .Visible = True

        Set doc = .Documents.Add
        doc.SaveAs CurrentProject.Path & "\TestDoc.doc"
    End With

    Set oRng = doc.Range

    'Insert Gray Table
    Set oTable = doc.Tables.Add(Range:=oRng, NumRows:=1, NumColumns:= _
                                1, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
                                wdAutoFitFixed)

    With oTable
        If .Style <> "Table Grid" Then
            .Style = "Table Grid"
        End If
        .ApplyStyleHeadingRows = True
        .ApplyStyleLastRow = False
        .ApplyStyleFirstColumn = True
        .ApplyStyleLastColumn = False
        .ApplyStyleRowBands = True
        .ApplyStyleColumnBands = False
    End With

    With oRng
        .Collapse 1
        .Text = "Council Report Summary" & vbCr & vbCr & _
                "The proposed development application does not comply with the requirements of Council's relevant policies." & vbCr & vbCr & _
                QueryA!ConditionCategory & vbCr & vbCr

        .ParagraphFormat.LineSpacingRule = wdLineSpaceSingle
        .ParagraphFormat.SpaceAfter = 0
        .ParagraphFormat.SpaceBefore = 0
        .Shading.Texture = wdTextureNone
        .Shading.ForegroundPatternColor = wdColorAutomatic
        .Shading.BackgroundPatternColor = -603937025
        .Font.Name = "Arial"
        .Font.Size = 11
        .Font.Bold = True
        .Font.Italic = False
        .Font.Bold = False
        .ParagraphFormat.Alignment = wdAlignParagraphLeft
        .Paragraphs(1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
        .Paragraphs(1).Range.Font.Bold = True
    End With
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote