2025年4月22日 星期二

VBA SVG 幼幼班

 SVG(可縮放向量圖形)是一種基於XML的圖像格式,適合透過VBA進行基礎操作。以下為結合VBA的幼幼班教學,從簡單形狀繪製到進階應用分階段說明:


p.s office 365 版本適用

基礎形狀繪製

步驟1:建立SVG檔案結構

Sub CreateBasicSVG()

    Dim svgContent As String

    svgContent = "<?xml version=""1.0"" encoding=""UTF-8"" standalone=""no""?>" & vbCrLf & _

                 "<svg width=""200"" height=""200"" xmlns=""http://www.w3.org/2000/svg"">" & vbCrLf

    ' 在此插入形狀代碼

    svgContent = svgContent & "</svg>"

    

    ' 儲存檔案

    Open "C:\BasicShape.svg" For Output As #1

    Print #1, svgContent

    Close #1

End Sub


步驟2:加入矩形

svgContent = svgContent & "<rect x=""50"" y=""50"" width=""100"" height=""60"" fill=""#FF0000""/>" & vbCrLf


步驟3:加入圓形

svgContent = svgContent & "<circle cx=""100"" cy=""100"" r=""40"" fill=""#00FF00""/>" & vbCrLf


Sub AddSVGToSlide()

    Dim shp As Shape

    Set shp = ActivePresentation.Slides(1).Shapes.AddShape(msoShapeRectangle, 100, 100, 200, 200)

     ' 設定圖形樣式為SVG

    shp.GraphicStyle = msoGraphicStyleFlat  ' 使用預設平面樣式[2]

    shp.Fill.UserPicture "C:\BasicShape.svg"  ' 載入外部SVG檔案

End Sub


沒有留言:

張貼留言

指數變化(2025.08.29) 開始透過AI做整理

 指數變化(2025.08.29) 開始透過AI做整理 上周焦點: 8/19(二)   美國房屋開工率 5%月增  美國建築許可月增率 月增2.8% 8/20(三)   美國房貸綜合指數 月減0.5%  美國30年期房貸利率 6.69%  美國15年期房貸利率 5.8~5.71%...