问题描述
我想在Excel工作表中从2010 Access vba中添加形状并对其进行修改。
I would like to add shapes and modify them from 2010 Access vba in an Excel worksheet.
我基于Excel记录宏编写的代码是:
The code I wrote based on Excel 'record macro' is:
StrSheetName = "Menu"
wkbModels.Sheets.Add(before:=wkbModels.Sheets("Models")).Name = StrSheetName
Set wksModelsMenu = wkbModels.Sheets(StrSheetName)
With wksModelsMenu
iLeft = 1
iTop = 1
iWidth = 125
iHeight = 200
.Shapes.AddPicture fDirectory & "logo.jpg", False, True, iLeft, iTop, iWidth, iHeight
iLeft = 240
iTop = 1
iWidth = 300
iHeight = 125
.Shapes.AddShape(msoShapeRoundedRectangle, iLeft, iTop, iWidth, iHeight).Select
.Shapes(1).Range.ShapeStyle = msoShapeStylePreset10
.Shapes(1).Range.TextFrame2.TextRange.Font.Bold = msoTrue
.Shapes(1).Range.TextFrame2.VerticalAnchor = msoAnchorMiddle
.Shapes(1).Range.TextFrame2.TextRange.Characters.Text = _
"TEST TEST TEST"
.Shapes(1).Range.TextFrame2.TextRange.Characters.ParagraphFormat.Alignment = msoAlignCenter
.Shapes(1).Range.TextFrame2.TextRange.Characters.Font.Bold = msoTrue
End With
在 .Shapes(1).Range.ShapeStyle ...和。之后。形状(1)。语句,我收到一个错误对象不支持此属性或方法。删除(1)会产生编译错误。
On the ".Shapes(1).Range.ShapeStyle..." and following ".Shapes(1)." statements I receive an error "Object doesn't support this property or method". Removing the "(1)" gives a compile error.
已安装mso库,并且引用的项(即msoShapeStylePreset10)具有正确的值。
The mso library is installed and the referenced items (i.e., msoShapeStylePreset10) have the proper values.
关于我需要做什么的任何想法?
Any ideas on what I need to do?
推荐答案
所以,它的作用是什么值得,我发现如果将索引从形状之后移动到范围之后,索引将根据需要运行。
So, for what it's worth, I found that if I moved the index from after the "Shapes" to after the "Range" it works as needed.
此:
Shapes(1).Range.....
更改为:
Shapes.Range(1)
当然,如果您看一下代码,就会看到第二种形状是我真正想要处理的。
Of course if you look at the code, you see that the second shape is what I really want to work on.
Shapes(2).Range
没有用。
Shapes.Range(2)
工作完美。
这篇关于2010 Access-如何在Excel文件中添加和使用形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!