shp.TextFrame2.TextRange.Text = region & vbCrLf & "销量: " & sales ' 设置形状内文本 Private Sub CommandButton1_Click() UpdateShapesWithSalesDataEnd SubSub UpdateShapesWithSalesData() Dim ws As Worksheet Dim cell As Range Dim shp As Shape Dim i As Integer Dim region A...
PrivateSubCommandButton1_Click()UpdateShapesWithSalesDataEndSubSubUpdateShapesWithSalesData()DimwsAsWorksheetDimcellAsRangeDimshpAsShapeDimiAsIntegerDimregionAsStringDimsalesAsDoubleDimcolorAsLong' 设置当前工作表对象Setws=ActiveSheet' 清除工作表中除了 CommandButton (Type为12) 外已有的所有形状,确保每次运行...
在事件过程中必须使用代码名称,在选择控件时必须使用形状名称。 Shape对象代表绘图层中的对象。例如自选图形、任意多边形、OLE对象或图片。 使用Selection.ShapeRange(index)可返回选定区域中的形状的Shape对象。 Worksheets(1).Shapes(1).Flip msoFlipHorizontal '↑ 将工作表一上的形状一进行水平翻转。 Worksheets(1)....
Set UserSelection=ActiveWindow.Selection On Error GoTo NoShapeSelected Set ActiveShape=ActiveSheet.Shapes(UserSelection.Name)On Error Resume Next MsgBox"左侧位置: "&ActiveShape.Left&vbNewLine&_"顶部位置: "&ActiveShape.Top Exit SubNoShapeSelected:MsgBox"没有选择形状!"End Sub 确定形状大小 可以使用VBA...
ActiveSheet.Shapes.AddShape(msoShapeRectangle, RG.Left, RG.Top, RG.Width, RG.Height).Select 'RG单元格左边单元格填写了图片名称,填充对应图片到矩形里。 Selection.ShapeRange.Fill.UserPicture "C:\" & RG.Offset(0, -1) & ".jpg" Next RG ...
Type:=msoShapeRectangle, _ Left:=Selection.Left, _ Top:=Selection.Top, _ Width:=Selection.Width, _ Height:=Selection.Height) On Error GoTo 0 '重命名该形状 shpBox.Name = shpBox.Name &"_MyRed" '格式化形状 shpBox.Fill.Visible = msoFalse ...
Set ooo = ActiveSheet.Shapes.AddShape(msoShapeDownArrow, 0, 0, 0, 0) 下箭头 With ooo .Top = mn.Top .Left = 158.25 .Width = 3.6 .Height = 33 End With ooo.Select Selection.ShapeRange.ShapeStyle = msoShapeStylePreset9 End If
Set shp=ActiveSheet.Shapes.AddShape(msoShapeRectangle, _ActiveCell.Left,_ActiveCell.Top,_rng.Width,_rng.Height)EndSub 方法2:可以手工按自己的意愿创建形状,然后使用VBA读取其宽度和高度。 Sub DetermineShapeSize()Dim ActiveShape As ShapeDim UserSelect...
Dim shp As Shape For Each shp In Selection.ShapeRange If shp.HasChart Then squareXYChartGrid shp.Chart,True, True End If Next Else MsgBox "选择一个或多个图表,再试试.",vbExclamation, "没有选择图表" End If End Sub 注:本文学习整理自peltiertech...
22 突出显示所选单元格并保留单元格格式(矩形)Highlight Selected Cells in Excel and Preserve Cell Formatting(Rectangles)Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)Dim RowShape As Shape, ColShape As Shape If Target.Address = Selection.EntireRow.Address ...