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
沒有留言:
張貼留言