automating Drop vsoSelection to vss file. vsoDoc1.Save '.... leads to MS warning box: "requested operation is presently disabled"

Kelvin4
Kelvin4 used Ask the Experts™
on
I'm trying to 'polish' the saving of a selected shape to an existing vss file that starts undocked.

I select some shapes:
vsoSelection1.Select MyShape, visSelect
which I wish to drop into vsoDoc1, an undocked vss file:

Set vsoDoc1 =Visio.Documents.OpenEx("C:\Users\Roger\Documents\MyShapes\ExportFromUserFile.vss", visOpenDocked + visOpenCopy)

'the selection is dropped, and then deleted from vst:    
vsoDoc1.Drop vsoSelection1, 0, 0
vsoSelection1.delete
'I want to save and close vsoDoc1, but:    
vsoDoc1.Save '.... leads to MS warning box: "requested operation is presently disabled"
vsoDoc1.Close

Can you please  show me how to save vsoSelection1 to  the named vsoDoc1:
avoiding: MS warning box: "requested operation is presently disabled". Indications of safe practice would be appreciated.

I also need to suppress the Microsoft security dialogue boxes that ask if macros should be enabled or disabled (I need my project macros enabled, and my project vss files accessible). This has security implications. Can you indicate how I should commence understanding my options and asking about best practice?  

Thanks in advance
Kelvin
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi Kelvin,

Here is some VBA code that creates a new master in the ActivePage's Document Stencil (the local stencil). All of the principles should apply to your case, I just wanted to avoid handling a second document in this sample, for clarity.

There's plenty of error checking and being-careful as it is. Hopefully the comments make it clear what's going on and why:

Option Explicit

Sub TestDropSelection()

  Dim pg As Visio.Page
  Set pg = Visio.ActivePage
  
  '// Create an empty selection from the page. Selection's
  '// don't have to be 'what you see selected on the page'. You can
  '// create them yourself as collections of shapes. But you have
  '// to initialize them correctly:
  Dim sel As Visio.Selection
  Set sel = pg.CreateSelection(Visio.VisSelectionTypes.visSelTypeEmpty)
  
  '// As dummy criteria, we will select all shapes on
  '// the left side of the page.
  
  '// Get the page's half-width:
  Dim wHalf As Double
  wHalf = pg.PageSheet.CellsU("PageWidth").ResultIU * 0.5
  
  '// Examine each shape on the page:
  Dim shp As Visio.Shape
  For Each shp In pg.Shapes
    If (shp.CellsU("PinX").ResultIU < wHalf) Then
      '// Shape is on the left half of the page:
      Call sel.Select(shp, Visio.VisSelectArgs.visSelect)
    End If
  Next shp
  
  Debug.Print "Selection ct: " & sel.Count
  
  '// Group the selection so that the master is a
  '// single shape. This is a best practice. If you don't
  '// do it, Visio will group the shapes inside the master
  '// on-drop anyway.
  
  '// If sel has more than one shape, we can group it. If
  '// only one, then we can just use that shape. If zero,
  '// then we can't create a new master. At any rate, we won't
  '// use sel to drop our new master.
  
  '// Define a shape that will be dropped as the master:
  Dim shpToDrop As Visio.Shape
  If (sel.Count > 1) Then
    Set shpToDrop = sel.Group
    '// If trying to get a shape from a group operation
    '// causes difficulty, just get the newest shape
    '// after grouping, ie:
    '// Call sel.Group
    '// Set shpToDrop = pg.Shapes.Item(pg.Shapes.Count)
  ElseIf (sel.Count = 1) Then
    Set shpToDrop = sel.Item(1)
  Else
    Set shpToDrop = Nothing
  End If
  
  '// After grouping, sel is no longer meaningful.
  Set sel = Nothing
  
  '// Create a master using the selection:
  Dim mst As Visio.Master
  If Not (shpToDrop Is Nothing) Then
    
    Set mst = pg.Document.Drop(shpToDrop, 0, 0)
    
    Debug.Print "Master name: " & mst.Name
    Debug.Print "Master shape ct: " & mst.Shapes.Count
    
    Set mst = Nothing
    
    Call shpToDrop.Delete
    Set shpToDrop = Nothing
    
  Else
    Debug.Print "No master created!"
  End If

End Sub

Open in new window

Author

Commented:
Thanks: it was a vague question, but your response was helpful and I learned from it.
Kelvin

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial