Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-19-2019, 11:29 AM
Christothex Christothex is offline Automatically format specific parts of a word document Windows 10 Automatically format specific parts of a word document Office 2019
Novice
Automatically format specific parts of a word document
 
Join Date: Oct 2019
Posts: 2
Christothex is on a distinguished road
Smile 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
Reply With Quote
  #2  
Old 10-19-2019, 12:30 PM
gmaxey gmaxey is offline Automatically format specific parts of a word document Windows 10 Automatically format specific parts of a word document Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,421
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

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 10-19-2019, 02:14 PM
Christothex Christothex is offline Automatically format specific parts of a word document Windows 10 Automatically format specific parts of a word document Office 2019
Novice
Automatically format specific parts of a word document
 
Join Date: Oct 2019
Posts: 2
Christothex is on a distinguished road
Default

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
Reply With Quote
  #4  
Old 10-19-2019, 09:06 PM
gmayor's Avatar
gmayor gmayor is offline Automatically format specific parts of a word document Windows 10 Automatically format specific parts of a word document Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
Reply

Tags
autoformat, formatting data, vba code

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically format specific parts of a word document Can Macros Automatically Format an Entire Document to My Specifications CrossReach Word VBA 4 11-14-2017 12:51 PM
Automatically format specific parts of a word document 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
Automatically format specific parts of a word document Adding and Moving parts of a document in Word PauledInAction Word 4 07-13-2012 02:38 PM
Automatically format specific parts of a word document Can you prevent parts of a Word document from printing? mgp69 Word 4 04-04-2012 02:12 PM

Other Forums: Access Forums

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