Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-19-2024, 08:05 PM
Jakov93 Jakov93 is offline Format selected table in academic style Windows 10 Format selected table in academic style Office 2019
Advanced Beginner
Format selected table in academic style
 
Join Date: Jul 2021
Posts: 51
Jakov93 is on a distinguished road
Default Format selected table in academic style

Hi,
Please I want format selected table in academic style by VBA code without applying manual styling for each table in my paper as following
314.png


Also, using alternate rows coloring (in some papers)
315.png
Thanks
Reply With Quote
  #2  
Old 11-19-2024, 09:07 PM
macropod's Avatar
macropod macropod is offline Format selected table in academic style Windows 10 Format selected table in academic style Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,359
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

From where are you getting the Academic Style?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 11-19-2024, 09:17 PM
Jakov93 Jakov93 is offline Format selected table in academic style Windows 10 Format selected table in academic style Office 2019
Advanced Beginner
Format selected table in academic style
 
Join Date: Jul 2021
Posts: 51
Jakov93 is on a distinguished road
Default

Thanks for reply,
Take look at any research paper and you will find academic style for tables, as many journals require that, for example

Just a moment...

Just a moment...

https://static.cambridge.org/binary/...ub-status=live

https://static.cambridge.org/binary/...48216_tab5.gif

Aripiprazole in the treatment of the psychosis
prodrome | The British Journal of Psychiatry | Cambridge Core
Reply With Quote
  #4  
Old 11-19-2024, 11:47 PM
macropod's Avatar
macropod macropod is offline Format selected table in academic style Windows 10 Format selected table in academic style Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,359
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Your links point to a variety of table layouts. It's impossible to know from that what you actually expect. It's also impossible to create a single table Style that accommodates all those formats.

The following macro creates an "Academic" table Style that might work in some scenarios.
Code:
Sub AcademicTableStyle()
With ActiveDocument
  .Styles.Add Name:="Academic", Type:=wdStyleTypeTable
  With .Styles("Academic")
    'Set the table body alignment
    .ParagraphFormat.Alignment = wdAlignParagraphRight
    With .Table
      'Set the alignments for the first column and row
      .Condition(wdFirstRow).ParagraphFormat.Alignment = wdAlignParagraphLeft
      .Condition(wdFirstColumn).ParagraphFormat.Alignment = wdAlignParagraphLeft
      'Make the first row Bold
      .Condition(wdFirstRow).Font.Bold = True
      'Set cell padding - to keep text away from edges
      .TopPadding = InchesToPoints(0)
      .BottomPadding = InchesToPoints(0)
      .LeftPadding = InchesToPoints(0.125)
      .RightPadding = InchesToPoints(0.125)
      'Clear all borders & shading
      .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
      .Borders(wdBorderRight).LineStyle = wdLineStyleNone
      .Borders(wdBorderHorizontal).LineStyle = wdLineStyleNone
      .Borders(wdBorderVertical).LineStyle = wdLineStyleNone
      .Shading.Texture = wdTextureNone
      .Shading.ForegroundPatternColor = wdColorAutomatic
      .Shading.BackgroundPatternColor = wdColorAutomatic
      'Set the bottom border for the table
      .Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
      .Borders(wdBorderBottom).LineWidth = wdLineWidth050pt
      .Borders(wdBorderBottom).Color = wdColorAutomatic
      'Set the top & bottom border for the first row
      .Condition(wdFirstRow).Borders(wdBorderBottom).LineStyle = wdLineStyleSingle
      .Condition(wdFirstRow).Borders(wdBorderBottom).LineWidth = wdLineWidth050pt
      .Condition(wdFirstRow).Borders(wdBorderBottom).Color = wdColorAutomatic
      .Condition(wdFirstRow).Borders(wdBorderTop).LineStyle = wdLineStyleSingle
      .Condition(wdFirstRow).Borders(wdBorderTop).LineWidth = wdLineWidth050pt
      .Condition(wdFirstRow).Borders(wdBorderTop).Color = wdColorAutomatic
      'Configure the row banding
      .Condition(wdOddRowBanding).Shading.Texture = wdTextureNone
      .Condition(wdOddRowBanding).Shading.ForegroundPatternColor = wdColorAutomatic
      .Condition(wdOddRowBanding).Shading.BackgroundPatternColor = wdColorGray125
      .Condition(wdEvenRowBanding).Shading.Texture = wdTextureNone
      .Condition(wdEvenRowBanding).Shading.ForegroundPatternColor = wdColorAutomatic
      .Condition(wdEvenRowBanding).Shading.BackgroundPatternColor = wdColorAutomatic
      'Set the table alignment
      .Alignment = wdAlignRowCenter
      'Set how many rows & columns to group for banding
      .RowStripe = 1
      .ColumnStripe = 0
    End With
  End With
End With
End Sub
Having run that macro once, you can then add tables employing that style with code like:
Code:
Sub AddTable()
Dim Tbl As Table
'Create a basic 4-row 3-column table that autofits the column width
Set Tbl = ActiveDocument.Tables.Add(Range:=Selection.Characters.Last, NumRows:=4, NumColumns:=3, DefaultTableBehavior:=wdWord8TableBehavior)
With Tbl
  'Make the first row repeat is the table spans a page break
  .Rows.First.HeadingFormat = True
  'Set the row height rules
  .Rows.HeightRule = wdRowHeightAtLeast
  .Rows.Height = InchesToPoints(0.25)
  'Apply the Academic Style
  .Style = "Academic"
  'Apply the row banding
  .ApplyStyleRowBands = True
End With
End Sub
If you look through the code, you should be able to see where you might modify it to change the appearance & formatting of the tables that get created.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 11-20-2024, 12:22 AM
Jakov93 Jakov93 is offline Format selected table in academic style Windows 10 Format selected table in academic style Office 2019
Advanced Beginner
Format selected table in academic style
 
Join Date: Jul 2021
Posts: 51
Jakov93 is on a distinguished road
Default

Thanks for your help
I just provide an examples for academic table style, which is in general has boarder for top and bottom and all other side none (the first image in my post).

Your first code each time make a style with the name academic and does not make sense, your second macro works fine for adding a new table, which is not my need, as I want to apply style of second macro for selected table.
Thanks
Reply With Quote
  #6  
Old 11-20-2024, 01:06 AM
macropod's Avatar
macropod macropod is offline Format selected table in academic style Windows 10 Format selected table in academic style Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,359
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by Jakov93 View Post
I just provide an examples for academic table style, which is in general has boarder for top and bottom and all other side none (the first image in my post).
Which is what I emulated.
Quote:
Originally Posted by Jakov93 View Post
Your first code each time make a style with the name academic and does not make sense, your second macro works fine for adding a new table, which is not my need, as I want to apply style of second macro for selected table.
Perhaps you didn't read where I said to run the AcademicTableStyle once. I even italicised the once to emphasize that.

You don't need to run the AddTable macro at all, if you don't want to. That's been provided just to hel[ ypu create new tables in the "Academic" Style. You should be able to select any existing table and apply the "Academic" Style to it, if that's all you want to do.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
List acronyms from selected tables after them with style Winrow Word VBA 6 06-25-2022 03:27 AM
Format selected table in academic style Word 2007: Unable to change character style, when using a linked Char/Para style format Last Chance Word 3 06-09-2021 12:52 PM
academic standard pagination in margin Tim-A Word 1 10-26-2016 05:18 AM
Format selected table in academic style Macro to apply style to selected tables ubns Word 1 08-02-2012 04:09 AM
Format selected table in academic style Specific format for an academic paper in finance Frednd Word 1 02-25-2011 04:55 PM

Other Forums: Access Forums

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