score:2
There are a number of possible approaches. One would be to not use wdReplaceAll
- instead, the code would do one "find" at a time, apply the required formatting, then loop the find/replace and format again and again until nothing more is found. There are lots of examples of this approach here on Stack Overflow and on the Internet, in general.
Quicker would be to leverage the fact that Word can apply certain kinds of formatting as part of the Replace functionality. In the Word UI, press Ctrl+H to view the Find & Replace dialog box; click "More" then click "Format" to see the possibilities. Bullets and Numbering is not a selection, here... But Styles are.
If you're working with a template to generate these documents (highly recommended) then define the bullets / numbering to be used as styles in the template. If no template is used, the code can create the style definition(s) on-the-fly.
Specify the Style name (case-sensitive!) as part of the Replacement
properties defined for the Find
and set the Format
property to True. Something like:
Dim rngFind as Word.Range 'Object if late-binding
Set rngFind = WordDoc.Content
With rngFind.Find
.ClearFormatting
.Replacement.ClearFormatting
.Replacement.Style = "My style"
.Format = True
.Execute FindText:=ReplacementTextF, ReplaceWith:=ReplacementText, Replace:=2
End With
Source: stackoverflow.com
Related Query
- How to set Replacement Text to Bullet Format when creating WordDoc from Excel using VBA
- How to extract all rows from excel data set when cell/column contains certain text
- How do I change text in a Word Doc from Excel VBA when Word Doc is located on a server?
- How can I avoid Line feeder in text file when I write the content from excel sheet?
- Cause of Error object variable or with block variable not set error 91 when extracting text from excel to word
- How to remove double quotation marks when converting from excel to text file?
- How to remove the LAST set Parentheses from a Excel text string that contains only numeric s
- How to convert the format of a cell from text to number when using forms to input data
- Set Excel spreadsheet values to wrap text automatically when inserting values from VBA form
- How do I permanently set the port to 9100 when printing from Excel VBA to the "ZPL Printer" Zebra label printer Chrome plug-in emulator
- How to read time stamp (DD/MM/YYYY) format from text file and correctly interpret it using Excel VBA?
- How to convert date and number format to text in excel so that when we query it using ODBC it returns the datafield as string
- How to set calculation mode to manual when opening an excel file?
- How can I write to a text file reliably from Excel VBA?
- Preserving "columns" when writing from a text file to excel using VBA
- How to set a range of different formulas to an Excel range from Delphi code?
- How can I copy one section of text from Word to Excel using an Excel macro?
- How to load vba macros to the excel file from a text file by a C# code?
- When multiple instances of Excel are open, how to set instance of Excel a manually-opened file is opened in?
- Excel VBA how to read in text file from web (not cached)?
- How to stop excel from changing data format to dates?
- Excel VBA How to convert cell format text to number
- How to export the data from excel to word as text use VBA
- How to set dropdown selection from code in Excel (VBA)
- How to remove leading zeros from alphanumeric text in excel
- How can I prevent Excel from opening a userform when opened from a macro in Outlook?
- How to keep formats when I copy a range from Excel to outlook
- How to keep rows which do not have a new line character from splitting, when importing the Body of a Lotus Notes e-mail into Excel using VBA?
- How to fix Compile Error: User-defined type not defined when using Excel VBA from Outlook?
- excel vba - how to extract a text from a given string
More Query from same tag
- For loop to skip specific rows
- VB Script for Outlook to automatically copy the file contents to a designated folder with a particular sender or based on Subject?
- How to check if there is an object already on the excel sheet, and if there isnt then insert the file?
- Excel VBA - How to duplicate / move an Hyperlink?
- Check if array is consecutive then delete values in between vba
- String Formatting Lost
- VBA datepart() function compile error "Expected: Expression"
- Microsoft Word VBA Macro - One Paragraph Find-Replace Styles
- Write in specific point of a docx document using vba
- PasteSpecial alternatives for better performance?
- Excluding weekends in a randomly generated non-repeating dates
- Comparing Excel files
- VBA Textbox : after entering each letter its skips to next row and column before entering the full word
- neat way to get last friday's date
- My Find function for a range, keeps starting at the 2nd instance, What am I doing wrong?
- Setting one range of cells equal to another without losing current selections
- In Excel VBA how can I determine how many worksheet tabs are currently within view across the bottom of the window..?
- Repetative task for each sheet, unhide and hide base on cell value
- InStr in Array not populating value if found
- Detect if Outlook is connected to Microsoft Exchange via company LAN or Wifi
- Selecting from Combobox Form Controls generates "Cannot run the macro" error
- Changing the index of a combobox in Excel from C#
- How to continually run function to count yellow cells?
- Excel shut down when I try open Macro
- Linking Data from One sheet into another on DropDown selection
- Read only one record from Multiple text files into Excel using VBA
- Passing a range of cells into a function in vba from excel
- Text Comparison from user input and a variable
- Use Personal.xlsb function in new workbook?
- Copy and Paste pictures by VBA Script on Windows 10 lock screen by scheduller or any app