Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-23-2021, 08:45 AM
santy2906 santy2906 is offline VBA macro to create word table Windows 10 VBA macro to create word table Office 2013
Novice
VBA macro to create word table
 
Join Date: Aug 2021
Posts: 1
santy2906 is on a distinguished road
Default VBA macro to create word table

Need help creating word table in vba in attached format.

so far I have this code:
Sub ChangeTableBorders(oWordTable As Word.table)
With oWordTable
.Spacing = 9


.Borders.InsideColor = wdColorBlue
.Borders.InsideLineStyle = wdLineStyleDashSmallGap
.Borders.OutsideColor = wdColorBlue
.Borders.OutsideLineStyle = wdLineStyleDashSmallGap
End With
End Sub

Sub ChangeTableRowBorder(oWordTableRow As Word.Row)
With oWordTableRow
.Shading.BackgroundPatternColor = wdColorAutomatic
.Borders(wdBorderBottom).Color = wdColorBlack
.Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
.Borders(wdBorderBottom).LineWidth = wdLineWidth050pt
End With
End Sub

I could not create that horizontal line due to spacing.

Any help would be highly appreciated!
Attached Images
File Type: png Table.PNG (2.9 KB, 17 views)
Reply With Quote
  #2  
Old 08-23-2021, 04:32 PM
Guessed's Avatar
Guessed Guessed is offline VBA macro to create word table Windows 10 VBA macro to create word table Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Why wouldn't you format the table how you want it and then save it as a Building Block? There is a seriously diminishing return on investment in trying to reproduce in code something that is easier to do other ways.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 08-23-2021, 09:18 PM
gmayor's Avatar
gmayor gmayor is offline VBA macro to create word table Windows 10 VBA macro to create word table Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,101
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 of
Default

I agree with Andrew, however ensure that you save the building block in the document template rather than the default normal template if anyone other than yourself is to use it.You can use the following to insert your autotext building block in a bookmark.
Code:
Sub AutoTextToBM(strbmName As String, oTemplate As Template, strAutotext As String)
'Graham Mayor - https://www.gmayor.com - Last updated - 10 Apr 2019
'strBMName is the name of the bookmark to fill
'oTemplate is the template with the autotext - probably ActiveDocument.AttachedTemplate
'strAutotext is the name of the autotext entry
Dim oRng As Range
    On Error GoTo lbl_Exit
    With ActiveDocument
        If .Bookmarks.Exists(strbmName) = True Then
            Set oRng = .Bookmarks(strbmName).Range
            Set oRng = oTemplate.AutoTextEntries(strAutotext).Insert _
                       (Where:=oRng, RichText:=True)
            .Bookmarks.Add Name:=strbmName, Range:=oRng
        End If
    End With
lbl_Exit:
    Exit Sub
End Sub
__________________
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
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA macro to create word table Macro to identify text - create table w/text & page numbers Cray_Z Word VBA 7 01-05-2021 09:32 PM
VBA macro to create word table How to I create a macro that dynamically creates a table, to enter questions, in the below format? MathiasFC Word VBA 11 01-14-2019 04:50 PM
VBA macro to create word table Need Help Macro That Uses Pivot Table to Create New Sheet Bob123456789 Excel Programming 13 03-14-2017 01:25 PM
Word Macro to delete table row and table header NorthSuffolk Word VBA 6 10-11-2016 05:04 AM
VBA macro to create word table Create Table Form from Word Document gsj224 Word VBA 3 07-31-2011 09:26 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:51 PM.


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