Solved

Table Style Not Applying Correctly via VBA

Posted on 2009-05-15
6
865 Views
Last Modified: 2012-05-07
I have a form where the user can click on check buttons to apply heading row formatting or last row formatting and they have a selection of my own table styles to choice from.

The problem I have is when a table already has heading row and last row formatting applied and then I run the form and tell it to not apply header row formatting or last row formatting.

It is almost like it doesn't activiate.  It removes the bolding which is correct and part of the table style but it won't remove the shading and lines.

If after you have run the code you click in the table and then click Table | AutoFormat then you will see that the ticks have been taken off but it hasnt been activated in the table.  If you press APPLY now manually it will work, but it doesnt work by code.

Any ideas how I can get this to activate fully?  I'm only new to code writing.
Private Sub CommandButton2_Click()
 
      
  'Turn all formatting features off
  
    With Selection.Tables(1)
        .ApplyStyleFirstColumn = False
        .ApplyStyleHeadingRows = False
        .ApplyStyleLastColumn = False
        .ApplyStyleLastRow = False
    End With
 
  'start my formatting here
  
   If ApplyTable.OBTableA = True Then
 
    With Selection.Tables(1)
        .Style = "My Table Grid"
         
        
                If ApplyTable.CBHeadingRow = True Then
                .ApplyStyleHeadingRows = True
                Else
               .ApplyStyleHeadingRows = False
                End If
 
               If ApplyTable.CBLastRow = True Then
               .ApplyStyleLastRow = True
             Else
               .ApplyStyleLastRow = False
               End If
 
        .ApplyStyleFirstColumn = False
        .ApplyStyleLastColumn = False
    
    End With
 
 
    Else
 
        With Selection.Tables(1)
            .Style = "My Table Normal"
 
 
               If ApplyTable.CBHeadingRow = True Then
                .ApplyStyleHeadingRows = True
                Else
                .ApplyStyleHeadingRows = False
                End If
 
             If ApplyTable.CBLastRow = True Then
               .ApplyStyleLastRow = True
               Else
               .ApplyStyleLastRow = False
               End If
            
            .ApplyStyleFirstColumn = False
            .ApplyStyleLastColumn = False
        
        End With
 
 
    End If
        
    Selection.Tables(1).Rows(1).Cells(1).Select
    Selection.Collapse Direction:=wdCollapseStart
    
    Unload ApplyTable
      
    
End Sub

Open in new window

0
Comment
Question by:Fi69
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 37

Expert Comment

by:Joanne M. Orzech
ID: 24416292
I'm just jumping in here real quick (and I don't have time to research this thoroughly right now) but.... maybe you can just reset the whole table to normal and then apply your styles?
    With Selection.Tables(1)
        .Style = "Table Normal"
    End With
 
or
 
 
     With Selection.Tables(1)
        .Style = "Table Normal"
        .ApplyStyleHeadingRows = True
        .ApplyStyleLastRow = False
        .ApplyStyleFirstColumn = True
        .ApplyStyleLastColumn = False
    End With

Open in new window

0
 

Author Comment

by:Fi69
ID: 24417389
I tried doing that but that doesn't work either.  To be honest I think it is a bug.
0
 
LVL 37

Assisted Solution

by:Joanne M. Orzech
Joanne M. Orzech earned 100 total points
ID: 24425628
Well, I know there were issues with Word 2003's table styles....

http://www.shaunakelly.com/word/tablestyles/index.html

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Accepted Solution

by:
Fi69 earned 0 total points
ID: 24427119
To fix this problem I have written code to do what the table style should do.
0
 
LVL 37

Expert Comment

by:Joanne M. Orzech
ID: 24432092
Good for you!
0
 

Author Comment

by:Fi69
ID: 24461218
Thanks for your comments
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question