As you noticed, when you open the stencil, the active document changes. You can change it to an editable document as follows:
Set visioApp = CreateObject("visio.application")
visioApp.Documents.AddEx ("")
Set visioPage = visioApp.ActiveWindow.Page
' Remember which window is active '
Set visioWindow = visioApp.ActiveWindow
Set visioStencil = visioApp.Documents.Add("BASFLO_M.VSS")
' Reactivate the drawing window '
visioWindow.Activate
visioPage.Drop visioStencil.Masters(1), 4, 4
visioApp.ActiveDocument.SaveAs "c:\temp\mydoc.vsd"
visioApp.ActiveDocument.Close
You can also use the link to the created document object and not rely on the active document:
Set visioApp = CreateObject("visio.application")
' Get a reference to the docment you are creating'
Set visioDoc = visioApp.Documents.AddEx("")
Set visioPage = visioApp.ActiveWindow.Page
Set visioStencil = visioApp.Documents.Add("BASFLO_M.VSS")
visioPage.Drop visioStencil.Masters(1), 4, 4
' Use the document object, not the active document '
visioDoc.SaveAs "c:\temp\mydoc1.vsd"
visioDoc.Close
. , , , -. , .. -, , . , - , . :
Set visioApp = CreateObject("visio.application")
' BASFLO_M.VST is the filename of the Basic Flowchart Template (metric) '
Set visioDoc = visioApp.Documents.Add("BASFLO_M.VST")
Set visioPage = visioApp.ActiveWindow.Page
' The stencil will be already open as part of the BASFLO_M.VST workspace '
Set visioStencil = visioApp.Documents("BASFLO_M.VSS")
visioPage.Drop visioStencil.Masters(1), 4, 5
visioPage.Drop visioStencil.Masters(1), 5, 4
visioDoc.SaveAs "c:\temp\mydoc2.vsd"
visioDoc.Close