Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 03-17-2016, 11:18 PM
gmayor's Avatar
gmayor gmayor is offline Adding tables to Created word document whilst other word document open Help Windows 10 Adding tables to Created word document whilst other word document open Help 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
 

Tags
add, tables, vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding furigana to a Word document rjribbit Word 0 12-03-2015 09:33 AM
Adding tables to Created word document whilst other word document open Help Inexperienced user having dificulty adding text to document I created. Fixed text moves around. Athalwolf Word 2 02-08-2015 09:08 AM
Adding tables to Created word document whilst other word document open Help Error message opening a document in Word "Word cannot open this file because it is larger than 512 M poonamshedge Word 2 09-11-2014 06:11 AM
Adding tables to Created word document whilst other word document open Help Adding and Moving parts of a document in Word PauledInAction Word 4 07-13-2012 02:38 PM
Adding bullets in a protected Word document Cindylu3 Word 0 10-03-2008 03:16 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:07 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft