Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-09-2023, 01:28 PM
puff puff is offline Change font color of a textbox on a canvas Windows 10 Change font color of a textbox on a canvas Office 2016
Advanced Beginner
Change font color of a textbox on a canvas
 
Join Date: Apr 2017
Posts: 60
puff is on a distinguished road
Question 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!
Reply With Quote
  #2  
Old 09-11-2023, 11:47 PM
Boris_R Boris_R is offline Change font color of a textbox on a canvas Windows Vista Change font color of a textbox on a canvas Office 2010 32bit
Novice
 
Join Date: Oct 2015
Posts: 6
Boris_R is on a distinguished road
Default

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
Reply With Quote
  #3  
Old 09-12-2023, 09:13 PM
puff puff is offline Change font color of a textbox on a canvas Windows 10 Change font color of a textbox on a canvas Office 2016
Advanced Beginner
Change font color of a textbox on a canvas
 
Join Date: Apr 2017
Posts: 60
puff is on a distinguished road
Default

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:
Originally Posted by Boris_R View Post
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
Reply With Quote
  #4  
Old 09-13-2023, 12:53 AM
Guessed's Avatar
Guessed Guessed is offline Change font color of a textbox on a canvas Windows 10 Change font color of a textbox on a canvas Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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

Tags
canvas, color



Similar Threads
Thread Thread Starter Forum Replies Last Post
Change font color of a textbox on a canvas VBA to change multiple change drop down font color and make bold bwhitlock Word VBA 1 08-08-2022 12:18 AM
Change font color of a textbox on a canvas 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
Change font color of a textbox on a canvas 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
Change font color of a textbox on a canvas Codes for Word Textbox Font Color? tinfanide Word VBA 7 10-23-2012 03:13 PM

Other Forums: Access Forums

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