TextBox对象自定义-编译错误:引用无效或不合格 [英] TextBox object customisation - Compile error: Invalid or unqualified reference

查看:74
本文介绍了TextBox对象自定义-编译错误:引用无效或不合格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Excel电子表格中添加一个这样的文本框:

我使用了以下查询:

如何使用VBA Excel自定义文本框?
如何设置自己的名称("Textbox1"以外的名称)?

解决方案

您尝试访问多个属性而不指定它们的属性.您需要这样的东西:

  Sub asbuiltstamp()设置myDocument =工作表(1)使用myDocument.Shapes.AddTextbox(msoTextOrientationHorizo​​ntal,800、50、200、75)使用.TextFrame.Horizo​​ntalAlignment = xlCenter带.Characters.Text =城市纤维"&vbLf&建成"带有.Font.Bold =真.ColorIndex = 3大小= 20结束于结束于结束于旋转= 45.Fill.Visible = False结束于结束子 

I would like a textbox like this in my Excel spreadsheet:

I used this query: VBA Shapes.AddTextbox Method

I modified the code:

Sub asbuiltstamp()
Set myDocument = Worksheets(1)
myDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, _
 800, 50, 200, 75) _
.TextFrame.Characters.Text = "City Fibre As-Built"
.Font.ColorIndex = 3
.Font.Size = 20
.Font.HorizontalAlignment = xlCenter
.Shapes.Rotation = 45
.Shapes.Fill = False

End Sub

I get:

Compile error: Invalid or unqualified reference.

How can I customise my textbox with VBA Excel?
How can I set its own name (other than "Textbox1")?

解决方案

You've tried to access several properties without specifying what they are properties of. You need something like this:

Sub asbuiltstamp()
   Set myDocument = Worksheets(1)
   With myDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, 800, 50, 200, 75)
      With .TextFrame
         .HorizontalAlignment = xlCenter
         With .Characters
        .Text = "City Fibre" & vbLf & "As-Built"
        With .Font
           .Bold = True
           .ColorIndex = 3
           .Size = 20
        End With
         End With
      End With
      .Rotation = 45
      .Fill.Visible = False
   End With

End Sub

这篇关于TextBox对象自定义-编译错误:引用无效或不合格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆