Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-23-2024, 12:45 AM
anmalogo anmalogo is offline Vertically center a test in the selected cell Windows 11 Vertically center a test in the selected cell Office 2021
Novice
Vertically center a test in the selected cell
 
Join Date: Apr 2024
Posts: 6
anmalogo is on a distinguished road
Default Vertically center a test in the selected cell

Hello all,

I have a Word VBA that basically change the font and the size of the text which in the the cells of a word table selected.

HTML Code:
Sub Macro4()
'ShortCut Ctrl + Shift + I
' Check if any text is selected
If Selection.Type = wdSelectionIP Then
    MsgBox "No text selected!", vbExclamation
    Exit Sub
End If
    
' Change font to Segoe UI, size 8, and color green
    With Selection.Font
        .Name = "Segoe UI"
        .Size = 8
        .Color = RGB(0, 0,0) ' Black color
    End With
End Sub
The problem is that I would like to also vertically center the text which in the cell, but since the Word file has many tables, I don't know how to select it.



I think I'm better codding Excel VBA, but to be honest, Word VBA give me headaches . I would really appreciate your help.

Thanks.
Reply With Quote
  #2  
Old 04-23-2024, 02:22 AM
vivka vivka is offline Vertically center a test in the selected cell Windows 7 64bit Vertically center a test in the selected cell Office 2016
Competent Performer
 
Join Date: Jul 2023
Posts: 227
vivka is on a distinguished road
Default

Hi! This will do the job on the selected tables:
Code:
Sub Format_Tables()
'
    For Each tbl In selection.Tables
        With tbl.range
            .Font.name = "Segoe UI"
            .Font.Color = RGB(0, 0, 0) 'Black color
             .Font.Size = 8
            .Cells.VerticalAlignment = wdCellAlignVerticalCenter
         End With
    Next tbl
End Sub
Reply With Quote
  #3  
Old 04-23-2024, 03:54 AM
anmalogo anmalogo is offline Vertically center a test in the selected cell Windows 11 Vertically center a test in the selected cell Office 2021
Novice
Vertically center a test in the selected cell
 
Join Date: Apr 2024
Posts: 6
anmalogo is on a distinguished road
Default

Quote:
Originally Posted by vivka View Post
Hi! This will do the job on the selected tables:
Code:
Sub Format_Tables()
'
    For Each tbl In selection.Tables
        With tbl.range
            .Font.name = "Segoe UI"
            .Font.Color = RGB(0, 0, 0) 'Black color
             .Font.Size = 8
            .Cells.VerticalAlignment = wdCellAlignVerticalCenter
         End With
    Next tbl
End Sub
Hello Vivka,

Thanks for your quick response, but your code is changing the whole table, not just the selected cell of the table . Do you know how to apply the code just to the selected cells of the table?. My table is quite big.

Thanks.
Reply With Quote
  #4  
Old 04-23-2024, 05:03 AM
gmaxey gmaxey is offline Vertically center a test in the selected cell Windows 10 Vertically center a test in the selected cell Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Code:
Sub Format_Tables()
  With Selection
    .Font.Name = "Segoe UI"
    .Font.Color = RGB(0, 0, 0) 'Black color
    .Font.Size = 8
    .Cells.VerticalAlignment = wdCellAlignVerticalCenter
  End With
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 04-24-2024, 01:31 AM
anmalogo anmalogo is offline Vertically center a test in the selected cell Windows 11 Vertically center a test in the selected cell Office 2021
Novice
Vertically center a test in the selected cell
 
Join Date: Apr 2024
Posts: 6
anmalogo is on a distinguished road
Default Many thanks gmaxey

It is working great.

Thanks, gmaxey!.
Reply With Quote
Reply

Tags
vba, vertically center, word 365



Similar Threads
Thread Thread Starter Forum Replies Last Post
Vertically center text on a page (was:Printing on 8x 10) slacy09 Word 4 09-27-2023 05:29 AM
Vertically Center Selected Range in the Useable Window gmaxey Word VBA 0 12-19-2020 10:01 AM
Vertically center a test in the selected cell How to vertically center text in a line SPO Word 4 01-18-2017 02:48 PM
How to Center One Line Vertically on Blank Page SQLUSA Word 1 08-29-2012 08:14 PM
Vertically center a test in the selected cell How vertically center text with enlarged bullet? judithvg PowerPoint 2 05-09-2012 02:18 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:51 AM.


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