Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-29-2021, 02:59 AM
Shelley Lou Shelley Lou is offline VBA convert to table - format Column 1 Windows 10 VBA convert to table - format Column 1 Office 2016
Competent Performer
VBA convert to table - format Column 1
 
Join Date: Dec 2020
Posts: 170
Shelley Lou is on a distinguished road
Default VBA convert to table - format Column 1

Hi Guys, I have a macro that converts text to table format which works fine but I want to fine tune it a bit. Column 1 is set to 2.7 width (house style). I want to further format Column 1 to be left aligned (not justified) and indented to 1". I've tried all sorts within the macro but nothing seem to be working and I would be very grateful if someone could help me. Many thanks, Shelley



Code:
Sub DPU_Tables()
    Selection.WholeStory
    Selection.Font.Name = "Arial"
    Selection.Font.Size = 10
    With Selection.ParagraphFormat
        .SpaceBefore = 0
        .SpaceBeforeAuto = False
        .SpaceAfter = 9
        .SpaceAfterAuto = False
        .LineSpacingRule = wdLineSpaceAtLeast
        .LineSpacing = 15
        .LineUnitBefore = 0
        .LineUnitAfter = 0
    End With
    Selection.ParagraphFormat.Alignment = wdAlignParagraphJustify
    Selection.ConvertToTable Separator:=wdSeparateByTabs, NumColumns:=2, _
        NumRows:=8, AutoFitBehavior:=wdAutoFitFixed
    With Selection.Tables(1)
        .Style = "Table Grid"
        .ApplyStyleHeadingRows = True
        .ApplyStyleLastRow = False
        .ApplyStyleFirstColumn = True
        .ApplyStyleLastColumn = False
    End With
   Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
    Selection.Columns(1).PreferredWidth = InchesToPoints(2.7)
    Selection.Columns.PreferredWidthType = wdPreferredWidthPoints
    Selection.Columns(2).PreferredWidth = InchesToPoints(3.63)
    Selection.ParagraphFormat.Alignment = wdAlignParagraphJustify
    Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    Selection.Borders(wdBorderTop).LineStyle = wdLineStyleNone
    Selection.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
    Selection.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
    Selection.Borders(wdBorderRight).LineStyle = wdLineStyleNone
    Selection.Borders(wdBorderHorizontal).LineStyle = wdLineStyleNone
    Selection.Borders(wdBorderVertical).LineStyle = wdLineStyleNone
    Selection.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
    Selection.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
End Sub
Reply With Quote
  #2  
Old 01-29-2021, 04:15 AM
gmayor's Avatar
gmayor gmayor is offline VBA convert to table - format Column 1 Windows 10 VBA convert to table - format Column 1 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,105
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

How about
Code:
Sub DPU_Tables()
Dim oBorder As Border
    Selection.WholeStory
    Selection.ConvertToTable Separator:=wdSeparateByTabs, NumColumns:=2, _
                             NumRows:=8, AutoFitBehavior:=wdAutoFitFixed

    With Selection.Tables(1)
        .Style = "Table Grid"
        .ApplyStyleHeadingRows = True
        .ApplyStyleLastRow = False
        .ApplyStyleFirstColumn = True
        .ApplyStyleLastColumn = False
        With .Range
            .Font.Name = "Arial"
            .Font.Size = 10
            With .ParagraphFormat
                .SpaceBefore = 0
                .SpaceBeforeAuto = False
                .SpaceAfter = 9
                .SpaceAfterAuto = False
                .LineSpacingRule = wdLineSpaceAtLeast
                .LineSpacing = 15
                .LineUnitBefore = 0
                .LineUnitAfter = 0
            End With
        End With

        With .Columns(1)
            .PreferredWidth = InchesToPoints(2.7)
            .Select
            With Selection.ParagraphFormat
                .Alignment = wdAlignParagraphLeft
                .LeftIndent = InchesToPoints(1)
            End With
        End With

        With .Columns(2)
            .Select
            With Selection.ParagraphFormat
                .Alignment = wdAlignParagraphJustify
            End With
            .PreferredWidth = InchesToPoints(3.63)
            For Each oBorder In .Borders
                oBorder.LineStyle = wdLineStyleNone
            Next oBorder
        End With
    End With
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
  #3  
Old 01-29-2021, 04:59 AM
Shelley Lou Shelley Lou is offline VBA convert to table - format Column 1 Windows 10 VBA convert to table - format Column 1 Office 2016
Competent Performer
VBA convert to table - format Column 1
 
Join Date: Dec 2020
Posts: 170
Shelley Lou is on a distinguished road
Default VBA convert to table - format Column 1

Thank you so much for replying Graham, the macro works fine except for the border around Column 1 - I can see the code is set to none so not sure why its got a border. Any ideas? Thanks, Shelley

Tables.JPG
Reply With Quote
  #4  
Old 01-29-2021, 05:26 AM
gmayor's Avatar
gmayor gmayor is offline VBA convert to table - format Column 1 Windows 10 VBA convert to table - format Column 1 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,105
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

copy the lines
Code:
For Each oBorder In .Borders
      oBorder.LineStyle = wdLineStyleNone
Next oBorder
from the .Columns(2) section, to the .Columns(1) section
__________________
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
  #5  
Old 01-29-2021, 05:44 AM
Shelley Lou Shelley Lou is offline VBA convert to table - format Column 1 Windows 10 VBA convert to table - format Column 1 Office 2016
Competent Performer
VBA convert to table - format Column 1
 
Join Date: Dec 2020
Posts: 170
Shelley Lou is on a distinguished road
Default VBA convert to table - format Column 1

Graham, you are the best, thank you so much that worked perfectly, many thanks, Shelley
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA convert to table - format Column 1 Macro to convert table to convert table into iCalendar file? Weboh Word VBA 5 12-10-2016 03:07 PM
VBA convert to table - format Column 1 Copying DNA from web and need to convert column date to ex: 11-15 JacMUr2 Excel 2 01-22-2016 03:36 AM
VBA to Format a Table Column in Excel Sgt Rock Excel 0 02-14-2015 02:54 PM
How can I temporarily break a 3 column format in order to type a single column paragraph William P Word 1 01-04-2015 06:40 PM
VBA convert to table - format Column 1 1.image in a table 2.right click 3.menu click format 4.a format column appears OldFatDog Drawing and Graphics 1 06-13-2014 11:19 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:36 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