#1
|
|||
|
|||
Change font color of a textbox on a canvas
Hi! I have a canvas with multiple textboxes on it. I select a textbox and want to change the font color of it using VBA, but it seems to be very hard to achieve this. Part of the reason seems to be that the selection itself is actually the canvas, not the specific textbox. Is there a way from the VBA perspective to know which textbox I selected? I then have no issue changing its font color since I can do so on textboxes that aren't on a canvas. Thanks!
|
#2
|
|||
|
|||
Try it, maybe it will help
Code:
Sub MyMacro1() Dim i As Long ' a shape's canvas item index On Error Resume Next '! y = Selection.Range.ShapeRange(1).CanvasItems.Count 'MsgBox Selection.Range.ShapeRange(1).CanvasItems(2).Name For i = 1 To y If Selection.Range.ShapeRange(1).CanvasItems(i).TextFrame.HasText Then ' Selection.Range.ShapeRange(1).CanvasItems(i).TextFrame.TextRange.Font.Name = "Times New Roman" Selection.Range.ShapeRange(1).CanvasItems(i).TextFrame.TextRange.Font.ColorIndex = wdBrightGreen End If Next ' WdColorIndex enumeration(Word) ' wdAuto 0 Automatic color. Default; usually black. 'wdBlack 1 Black color. 'wdBlue 2 Blue color. 'wdBrightGreen 4 Bright green color. 'wdByAuthor -1 Color defined by document author. 'wdDarkBlue 9 Dark blue color. 'wdDarkRed 13 Dark red color. 'wdDarkYellow 14 Dark yellow color. 'wdGray25 16 Shade 25 of gray color. 'wdGray50 15 Shade 50 of gray color. 'wdGreen 11 Green color. 'wdNoHighlight 0 Removes highlighting that has been applied. 'wdPink 5 Pink color. 'wdRed 6 Red color. 'wdTeal 10 Teal color. 'wdTurquoise 3 Turquoise color. 'wdViolet 12 Violet color. 'wdWhite 8 White color. 'wdYellow 7 Yellow color. End Sub |
#3
|
|||
|
|||
Thanks for the response but it does nothing on my side. Also it seems like the logic is to make a textbox's font into green as long as that textbox has text, which is not my case. I have multiple textbox on the canvas and they all have texts. I only want to change the font color for the textbox I selected, not all of them which have text.
Quote:
|
#4
|
||||
|
||||
Perhaps this is being over-thought. This works if you have selected a text box inside a Canvas
Code:
Sub Macro1() If Selection.ShapeRange.Count > 0 Then Selection.WholeStory 'needed if selection is inside textbox rather than being the textbox Selection.Font.ColorIndex = wdRed End If End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
Tags |
canvas, color |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
VBA to change multiple change drop down font color and make bold | bwhitlock | Word VBA | 1 | 08-08-2022 12:18 AM |
Word 16/19 change font and outside border color (same color) eg is red change to pink | jec1 | Word VBA | 2 | 12-04-2019 11:32 PM |
VBA change font color to background color | donaldadams1951 | Word VBA | 6 | 05-31-2018 04:36 PM |
Canvas + textbox + group = weird ghost bug? | somads | Word | 0 | 11-25-2015 01:37 AM |
Codes for Word Textbox Font Color? | tinfanide | Word VBA | 7 | 10-23-2012 03:13 PM |