1. vba shapes.addpicture
Sub 宏1()
Dim Sh As Shape
Set Sh = ActiveSheet.Shapes.AddShape(msoShapeOval, 60, 60, 90, 90)
Sh.Fill.ForeColor.RGB = RGB(255, 0, 0)
Set Sh = Nothing
End Sub把代码中的数字换成sheet2的单元格数据就可以了
2. excel vba cells属性
sub test() public sz() for i=1 to 10 sz(i)=cells(i) end if msgbox sz(3) erase sz() end sub 这段代码我还没有测试过,主要的意思是在使用完数组之后使用ERASE释放数组。
3. shape在vba中的用法
VBA遍历所有单元格
Sub test() Dim str Dim i, j i = 1 j = 1 For r = 1 To Worksheets(2).UsedRange.Rows.Count For c = 1 To Worksheets(2).UsedRange.Columns.Count str = Worksheets(2).Cells(r, c).Value Worksheets(3).Cells(j, 1).Value = i Worksheets(3).Cells(j, 2).Value = c Worksheets(3).Cells(j, 3).Value = str j = j + 1 Next i = i + 1 Next End Sub 删除形状 Sub test() Dim sheet As Worksheet Dim s As Shape Dim i As Integer For Each sheet In ActiveWorkbook.Sheets For Each s In sheet.Shapes s.Delete i = i + 1 Next Next MsgBox "已删除当前表中 " & i & " 形状" End Sub
4. excel vba shapes
加法例子:RAGE("A3") = RANGE("A1" + RANGE("A2")减法类似,使用运算符-代替上面的+就可以了
5. vba shapes属性
把图片复制到单元格,调整单元格大小至适合图片,可用ALT键+鼠标挪动图片,以锚定左上角,再调整右下角单元格至图片等于单元格大小。
然后右键图片,选属性--选“大小位置均随单元格改变"--确定
此时调整单元格则图片也随之调整了。
以下是你需的VBA代码,你可以用宏录制一个快捷键,删除中间代码。每在当前单元格插入一张图片,就执行一次宏。
Sub InsertPic()
cColumn = ActiveCell.Column
rRow = ActiveCell.Row
n = Sheet1.Shapes.Count
ActiveSheet.Shapes("Picture " & n).Select
Selection.ShapeRange.LockAspectRatio = msoFalse
Selection.ShapeRange.Width = ActiveSheet.Columns(cColumn).ColumnWidth * 6.44
Selection.ShapeRange.Height = ActiveSheet.Rows(rRow).RowHeight
With Selection
.Placement = xlMoveAndSize
.PrintObject = True
End With
End Sub
- 相关评论
- 我要评论
-