Execl巨集畫圖&加入刪除sub

Excel學習112

Option Explicit
Const topleft As String = "C5"  ' anchor cell
Const diam As Integer = 180     ' points
' 劉任昌提示參考 https://excelatfinance.com/xlf19/xlf-qg-add-blue-circle.php

Sub xlfAddCircle1() '副程式 sub 結束end sub
Dim Shp As Shape
Dim TLCleft As Double
Dim TLCtop As Double
 
        TLCleft = Range(topleft).Left
        TLCtop = Range(topleft).Top
 
        Set Shp = ActiveSheet.Shapes.AddShape(Type:=msoShapeOval, _
                                              Left:=TLCleft, Top:=TLCtop, _
                                              Width:=diam, Height:=diam)
        With Shp
                .Fill.Visible = msoFalse
                .Line.Weight = 10
                .Line.ForeColor.Brightness = 0.4
                .ThreeD.BevelTopType = msoBevelCircle
        End With
End Sub
Sub 萬宜芸() '副程式 sub 結束end sub
Dim Shp As Shape
Dim TLCleft As Double '距離左邊Left
Dim TLCtop As Double  '距離頂端Top
Dim i As Integer '宣告整數
        TLCleft = 10 '距離左邊Left
        TLCtop = 10  '距離頂端Top
   For i = 0 To 10 '迴圈畫多個圈
      TLCleft = TLCleft + 20
      TLCtop = TLCtop + 20
      Set Shp = ActiveSheet.Shapes.AddShape(Type:=msoShapeOval, _
                                              Left:=TLCleft, Top:=TLCtop, _
                                              Width:=diam, Height:=diam)
      With Shp
           .Fill.Visible = msoFalse
           .Line.Weight = 10
           .Line.ForeColor.Brightness = 0.4
           .ThreeD.BevelTopType = msoBevelCircle
      End With
   Next
End Sub

Excel學習113

'https://excelatfinance.com/xlf19/xlf-qg-add-blue-circle.php
Option Explicit
Const topleft As String = "C5"  ' anchor cell
Const diam As Integer = 100     ' 宣告常數constant diam 100
Dim Shp As Shape  'global variables全域變數
Sub 萬宜芸()
Dim TLCleft As Double
Dim TLCtop As Double
Dim i As Integer '宣告整數integer i
For i = 1 To 20  'write a loop單引號註解
     TLCleft = 20 * i '距離左邊left
        TLCtop = 20 * i '距離上面top
 '使用中的試算表active sheet. addshape(type, left, top, width, height)
Set Shp = ActiveSheet.Shapes.AddShape(msoShapeOval, TLCleft, TLCtop, 2 * diam, diam)
        With Shp
                .Fill.Visible = msoFalse
                .Line.Weight = 10
                .Line.ForeColor.Brightness = 0.4
                .ThreeD.BevelTopType = msoBevelCircle
        End With
    Next
    With Cells(1, 1)
      .Value = "鱷魚喝威士忌" '在儲存格1,1放入字串
      .Interior.Color = RGB(0, 0, 255)
      .Columns.AutoFit
      With .Font
      .Size = 30
      .Color = RGB(255, 255, 255)
      .Bold = True
      End With
   End With
End Sub
Sub 萬宜芸刪除()
   For Each Shp In ActiveSheet.Shapes 'Shp 共用的物件宣告成全域變數
      Shp.Delete  'programming .method delete .property, font color
   Next
End Sub

留言

這個網誌中的熱門文章

老師示範

EXCEL, WORD AddShape,網頁SVG