{"id":5498,"date":"2021-11-15T13:04:53","date_gmt":"2021-11-15T13:04:53","guid":{"rendered":"https:\/\/lgildv5i97.onrocket.site\/answers\/?post_type=question&#038;p=5498"},"modified":"2021-11-15T13:05:17","modified_gmt":"2021-11-15T13:05:17","slug":"excel-vba-to-format-a-textbox","status":"publish","type":"question","link":"https:\/\/computing.net\/answers\/office\/excel-vba-to-format-a-textbox\/19594.html","title":{"rendered":"Excel VBA To Format A Textbox"},"content":{"rendered":"<p>Hi All<br \/>\nI&#8217;m going round in circles trying to solve this one.<br \/>\nI simply want to open an an excel file go to the first sheet in the file and change the text colour of textbox1 to red.<\/p>\n<p>The only way I have managed to do it so far is via recording the macro.<br \/>\nIt gives me<\/p>\n<p>Workbooks.Open (fPath &amp; sName)<\/p>\n<p>Sheets(1).Select<\/p>\n<p>ActiveSheet.Shapes.Range(Array(&#8220;TextBox1&#8221;)).Select<\/p>\n<p>With Selection.ShapeRange(1).TextFrame2.TextRange.Characters(1, 262).Font.Fill<br \/>\n.Visible = msoTrue<br \/>\n.ForeColor.RGB = RGB(255, 0, 0)<br \/>\n.Transparency = 0<br \/>\n.Solid<br \/>\nEnd With<\/p>\n<p>That&#8217;s fine however the length of the text is variable so I get an error with the code if it is less than the 262 characters above.<\/p>\n<p>I tried to introduce<br \/>\nCharCount = Len(textbox1.Text)<\/p>\n<p>However I get error 424 Object required<\/p>\n<p>I initially tried<br \/>\nSheets(1).Select<br \/>\nActiveSheet.TextBox1.ForeColor = RGB(255, 0, 0)<\/p>\n<p>but got error 438 Object doesn&#8217;t support this property or method.<\/p>\n<p>Thanks for your help.<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"iawp_total_views":6},"question-category":[53],"question_tags":[],"class_list":["post-5498","question","type-question","status-publish","hentry","question-category-office"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question\/5498","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question"}],"about":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/comments?post=5498"}],"wp:attachment":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/media?parent=5498"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question-category?post=5498"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question_tags?post=5498"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}