VBA for Visio 2013 to save as SVG

▼魔方 西西 提交于 2020-01-16 00:59:10

问题


I need a macro which will allow me to save the current Visio drawing as an SVG file.

The quickest way I can do at the moment is to use the F12 keyboard shortcut which gives me the Save As dialog, but still each time I have to select the proper output file, i.e. PNG, and then write the name of the file.

Is it possible to automate this? I was looking for something like Macro recording in Visio, but couldn't find that.


回答1:


For file formats of .bmp, .dib, .dwg, .dxf, .emf, .emz, .gif, .htm, .jpg, .png, .svg, .svgz, .tif, or .wmf

The extension will define the format.

Dim vsoPage As Visio.Page 
Set vsoPage = ActivePage 
vsoPage.Export ("C:\\myExportedPage.svg") 

Here is an example of looping all pages exporting each one.

Dim PgObj    As Visio.Page 
Dim Pgs      As Visio.Pages 
Dim filename As String 
Dim PgName   As String 
Dim iPgs     As Integer 

'Set a handle to the pages collection
Set Pgs = Application.ActiveDocument.Pages 

'Loop Pages collections
For iPgs = 1 To Pgs.Count 
    'Set a handle to a page
    Set PgObj = Pgs(iPgs) 

    'Get Page name
    PgName = PgObj.Name 
    'Create path to save svg file
    filename = Application.ActiveDocument.Path & PgName & ".svg" 
    'Export the page as svg file
    PgObj.Export filename 
Next iPgs 

'Clean Up
Set PgObj = Nothing 
Set Pgs = Nothing 


来源:https://stackoverflow.com/questions/31791041/vba-for-visio-2013-to-save-as-svg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!