Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-18-2021, 02:59 AM
Guessed's Avatar
Guessed Guessed is offline VBA quote mark to insert after square bracket Windows 10 VBA quote mark to insert after square bracket Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,185
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

I didn't fiddle with the semi colon endings because your very first 'fixed' paragraph broke the rule of [sentences to end with a semi-colon]. - so it wasn't particularly clear what you wanted there. This code assumes your table formatting is done by the Table Style definitions. I've attached a result document with table style defined to match your look.
Code:
Sub DefinitionsTabulator()
  Dim aRng As Range, aTbl As Table, aPara As Paragraph, aCell As Cell
  Set aRng = ActiveDocument.Range

  For Each aPara In aRng.Paragraphs
    aPara.Range.Words.Last.Font.Reset     'remove bold from paragraph marks and autonumbers
  Next aPara

  With aRng.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "[:;, ^t]{1,5}means[:;, ]{1,5}"
    .Replacement.Text = "^t"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
    .Execute Replace:=wdReplaceAll
    
    .Text = "[ :]{1,5}^13"
    .Replacement.Text = ":^p"
    .Execute Replace:=wdReplaceAll
    
    Set aRng = ActiveDocument.Range
    aRng.ListFormat.ConvertNumbersToText
    
    .Text = "^13([a-z])\)"
    .Replacement.Text = "^13(\1)"
    .Execute Replace:=wdReplaceAll
    
    .Text = "^13(?)"
    .Replacement.Text = "|\1"
    .MatchWildcards = True
    .Font.Bold = False
    .Execute Replace:=wdReplaceAll
    
    .Text = "(?)^t"
    .Replacement.Text = "\1zzTabzz"
    .Font.Bold = False
    .Execute Replace:=wdReplaceAll
  End With
  
  Set aRng = ActiveDocument.Range
  Set aTbl = aRng.ConvertToTable(Separator:=wdSeparateByTabs, NumColumns:=2, AutoFitBehavior:=wdAutoFitFixed)
  With aTbl
    .Style = "Table Grid Light"     'choose a table style that matches your preferred table look
    .ApplyStyleHeadingRows = False
    .ApplyStyleLastRow = False
    .ApplyStyleFirstColumn = True     'make sure the table style has a bold first column
    .ApplyStyleLastColumn = False
    .Range.Style = wdStyleNormal
    For Each aCell In .Columns(1).Cells
      If aCell.Range.Characters.First = "[" Then
        aCell.Range.Characters.First.InsertAfter Text:=""""
        aCell.Range.Characters.Last.InsertBefore Text:=""""
      Else
        aCell.Range.Characters.First.InsertBefore Text:=""""
        aCell.Range.Characters.Last.InsertBefore Text:=""""
      End If
    Next aCell
  End With
  
  'Reinstate the tabs and paragraphs
  With aRng.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .MatchWildcards = False
    .Text = "|"
    .Replacement.Text = "^p"
    .Execute Replace:=wdReplaceAll
    
    .Text = "zzTabzz"
    .Replacement.Text = "^t"      'or a space if you prefer
    .Execute Replace:=wdReplaceAll
  End With
End Sub
Your style definitions should be in your template already and not fiddled by the macro. Try to avoid overly complicating the formatting by using vba code that SHOULD be done by the already existing style definition - just use the vba to apply the style.
Attached Files
File Type: docm Result.docm (42.2 KB, 7 views)
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #2  
Old 06-18-2021, 03:34 AM
Shelley Lou Shelley Lou is offline VBA quote mark to insert after square bracket Windows 10 VBA quote mark to insert after square bracket Office 2016
Expert
VBA quote mark to insert after square bracket
 
Join Date: Dec 2020
Posts: 259
Shelley Lou is on a distinguished road
Default VBA quote mark after square bracket in definitions

Hi Andrew, thanks for looking at this much appreciated. Just looking through the first part, after wording 'remove bold from paragraph marks and autonumbers what do the functions do as I would like to put in comments to remind me what the functions are, will have a test of some docs see how it works
Reply With Quote
  #3  
Old 06-18-2021, 06:41 AM
Shelley Lou Shelley Lou is offline VBA quote mark to insert after square bracket Windows 10 VBA quote mark to insert after square bracket Office 2016
Expert
VBA quote mark to insert after square bracket
 
Join Date: Dec 2020
Posts: 259
Shelley Lou is on a distinguished road
Default VBA quote mark to insert after square bracket

Hi Andrew, I've run the macro but there are some issues. I've attached a word doc showing these. For each sub-para e.g. (a), (i), (A), (1) these need to be in their own row individually. Not sure where I should be applying the column styles. For column 1 it will be "DefBold" and column 2 will be 'Definition Level 1'. Also for formatting the table for column width, no border etc. as in my table macro, I've inserted in various spaces but nothing seems to work.


VBA Defs doc.docx
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Block Quote into Numbered List krose4088 Word 4 12-10-2020 02:29 PM
VBA quote mark to insert after square bracket Delete blank paragraph below bold, end square bracket Dave T Word VBA 2 04-28-2019 11:00 PM
VBA quote mark to insert after square bracket Remove repeated number after square bracket jeffreybrown Word VBA 8 12-04-2018 06:01 PM
Word 2010 - Remove square-bracket encased string in large document IntestinalWorm Word 1 06-20-2017 01:14 AM
VBA quote mark to insert after square bracket Insert caption to graphic with square text wrapping nothing_kills Drawing and Graphics 7 01-20-2014 10:57 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:42 AM.


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