#1
|
|||
|
|||
Automatically format specific parts of a word document
Hi guys,
Is it possible to have a script that will automatically edit certain parts of a word document. I currently have a standardized form, so I am trying to make every forms released to be the same. For example, names in section A should be all capitalized, with a specific font and size. "address" section should be in a different font than the name. Date should be in MM DD, YYYY format (October 10, 2019). As we're handling thousands of form I believe this would help the admins in editing. Much Thanks, Chris |
#2
|
|||
|
|||
As long as those parts have a defined range, then yes.
A defined range can lots of things. A table cell, a bookmark, and content control, a paragraph etc. E.g., With ActiveDocument.SelectContentControlsByTitle("Name" ).Item(1) .Range.Text = UCase(.Range.Text) .Range.Font.NameLocal = "Arial .Range.font.Size = 12 End With |
#3
|
|||
|
|||
Hi Greg, thank you for your input
Say I wanted to select the top table cell in word, make all the letters there uppercase. How to select a cell in word? Does it work like excel? Much Thanks |
#4
|
||||
|
||||
It is not quite the same as Excel, but as Greg suggests it is just a matter of setting a range to the place you want to process. e.g.
Code:
Sub Macro1() Dim oTable As Table Dim oCell As Range Set oTable = ActiveDocument.Tables(1) 'where 1 is the first table 'or 'Set oTable = Selection.Tables(1) 'which is the table the cursor is in Set oCell = oTable.Rows(1).Cells(1).Range 'the first cell in the top row oCell.End = oCell.End - 1 'omit the cell end character from the range oCell.Text = UCase(oCell.Text) 'make the cell range upper case Set oCell = Nothing Set oTable = Nothing End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
Tags |
autoformat, formatting data, vba code |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Can Macros Automatically Format an Entire Document to My Specifications | CrossReach | Word VBA | 4 | 11-14-2017 12:51 PM |
Pulling parts of a webpage down to Word document | Bungkai | Word VBA | 1 | 12-17-2015 10:48 PM |
Add pictures in specific parts of the document and resize them automatically - MS Word 2013 | Andrew_G93 | Word | 6 | 11-10-2015 09:00 AM |
Adding and Moving parts of a document in Word | PauledInAction | Word | 4 | 07-13-2012 02:38 PM |
Can you prevent parts of a Word document from printing? | mgp69 | Word | 4 | 04-04-2012 02:12 PM |