Change Colour of certain part of a Table Cell - WORD

Chrisjd2

Board Regular
Joined
Mar 1, 2016
Messages
61
Hi Gents,

Hopefully this is pretty self-explanatory, If you see my code below, I want to only change the Font Color to the text within "societyname" not the actual text quoted before it.

How can I do this? This is in MSWord.

Hopefully you can help.

Cheers
Chris

Code:
objTable.Cell(1, 1).Range = "SOCIETY NAME: " & societyname
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
With code like:
Code:
Dim Rng As Range
Set Rng = objTable.Cell(1, 1).Range
With Rng
  .End = .End - 1
  .Text = "SOCIETY NAME: "
  .Collapse wdcollpaseend
  .Text = societyname
  .Font.ColorIndex = wdRed
End With
 
Upvote 0
With code like:
Code:
Dim Rng As Range
Set Rng = objTable.Cell(1, 1).Range
With Rng
  .End = .End - 1
  .Text = "SOCIETY NAME: "
  .Collapse wdcollpaseend
  .Text = societyname
  .Font.ColorIndex = wdRed
End With

It doesnt like ".End = .End - 1"

Would there be an easier way to do all the variables I am putting into the cells? They all need to be red and Bold.

Thanks in advance.

Cheers
Chris

Code:
Sub EnterTrial(KCName1, KCNo1, DOB1, Breed1, Sex1, Breeder1, Sire1, Dam1, Owner1, Owner1Address, Owner1Phone, Owner1Mobile, Owner1Email, Handler, HandlerAddress, HandlerPhone, HandlerMobile, HandlerEmail)

Dim dir As String
Dim objWord As Object
Dim objDoc As Object
Dim ExcelRow As String
Dim cRow As Long
Dim LastDog As Long
Dim ws As Worksheet
Dim wsDogs As Worksheet
Dim wsSociety As Worksheet
Dim DogRange As Range
Dim rng As Range
ExcelRow = Application.Caller


Set ws = Worksheets("Trials")
Set wsSociety = Worksheets("Societies")
Set wsDogs = Worksheets("Dogs")


dir = Application.ActiveWorkbook.Path & "\Trial Entry Form - Blank.DOC"


Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open(dir)
Set objTable = objDoc.Tables(1)


objWord.Visible = True




societyname = ws.Cells(ExcelRow, 2)
IDNo = ws.Cells(ExcelRow, 3)
StakeNo = ws.Cells(ExcelRow, 4)
EntriesClose = ws.Cells(ExcelRow, 8)
EntryFees = ws.Cells(ExcelRow, 10)




objTable.Cell(1, 1).Range = "SOCIETY NAME: " & societyname
objTable.Cell(1, 2).Range = "ID No.: " & vbCr & IDNo
objTable.Cell(1, 3).Range = "Stake No.: " & Chr(13) & Chr(9) & StakeNo
objTable.Cell(1, 4).Range = "Entries Close: " & Chr(13) & EntriesClose
objTable.Cell(2, 3).Range = "Entry Fees: " & EntryFees


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''' DOG ROUTINE '''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


objTable.Cell(4, 2).Range = KCName1
objTable.Cell(4, 3).Range = KCNo1
objTable.Cell(4, 4).Range = Breed1
objTable.Cell(4, 5).Range = Sex1
objTable.Cell(4, 6).Range = DOB1
objTable.Cell(4, 7).Range = Breeder1
objTable.Cell(4, 8).Range = Sire1
objTable.Cell(4, 9).Range = Dam1


objTable.Cell(8, 2).Range = QualificationDate
objTable.Cell(8, 3).Range = Award
objTable.Cell(8, 4).Range = Stake
objTable.Cell(8, 5).Range = Society


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


objTable.Cell(7, 5).Range = "Name of Owner(s): " & Owner1
objTable.Cell(8, 6).Range = "Address: " & Chr(13) & Owner1Address
objTable.Cell(9, 6).Range = "Phone: " & Owner1Phone
objTable.Cell(9, 7).Range = "Mobile: " & Owner1Mobile
objTable.Cell(10, 6).Range = "Email: " & Owner1Email


objTable.Cell(13, 2).Range = "Name of Handler: " & Handler
objTable.Cell(14, 2).Range = "Address: " & Chr(13) & HandlerAddress
objTable.Cell(15, 2).Range = "Phone: " & HandlerPhone
objTable.Cell(15, 3).Range = "Mobile: " & HandlerMobile
objTable.Cell(16, 2).Range = "Email: " & HandlerEmail






objWord.Activate






'objWord.Quit


End Sub
 
Last edited:
Upvote 0
It doesnt like ".End = .End - 1"
It does if you're running the code from within Word. Since you're running it from another app, you need to redefine Rng appropriately (i.e. Dim Rng as Object).
Would there be an easier way to do all the variables I am putting into the cells? They all need to be red and Bold.
Not really.
 
Last edited:
Upvote 0
Thanks for your reply, that fixed the error for .End = .End -1. However it didn’t change the text color? Do I have to make “wdcollpassend” and “wdred” equal something?

Cheers
Chris
 
Upvote 0
You should be using Option Explicit; that way you'd be warned about things like wdcollpaseend and wdRed. Replace them with 0 and 6, respectively.
 
Upvote 0

Forum statistics

Threads
1,214,621
Messages
6,120,563
Members
448,972
Latest member
Shantanu2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top