Code stops without error When Adding a Master to Page

Started by jik_ff, July 21, 2014, 07:34:52 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jik_ff

Not sure why this is happening, but the code just stops when aShape shape is added to the page.  The shape is there, but the rest of the code is not running (which has had me pulling my hair out for the last 1/2 hour thinking the next lines of codes where the problem):

Private Sub MakeModule(pVar As Integer)

    On Error GoTo 0
   
    'MsgBox "adding Module"
    'set constants for the 2 columns of Module blocks
    Const c1 As Double = 0.125
    Const c2 As Double = 16.75
    Const yStart As Double = 15
    'set the difference in Y pos for each row of module blocks
    Const deltaY As Double = -4.625
   
    Dim slotList As Variant
   
    Dim pX As Double
    Dim pY As Double
   
    'vars to get Document Stencil Masters list
    Dim vMasters As Visio.Masters
    Dim aMaster As Visio.Master
    Dim aShape As Visio.Shape
    Dim aPage As Visio.Page
   
    pX = 0
    pY = 0
   
    slotList = Array("A", "B", "C", "D", "E", "F", "G", "H")
   
    Debug.Print "Slot is " & slotList(pVar)
   
    'determine where the module will be placed
    If (pVar Mod 2 = 0) Then
        'even number, placed on the right
        pX = c2
    Else
        'odd number, place on the left
        pX = c1
    End If
    'set the y pos.
    pY = yStart + (deltaY * (RoundUP(pVar / 2) - 1))
   
   
    'get Document Stencil Masters container
    Set vMasters = Application.ActiveDocument.Masters
    Set aMaster = vMasters("Module")
    Set aPage = Me.Application.ActivePage
   
    aShape = aPage.Drop(aMaster, pX, pY)  '**********CODE STOPS HERE**********
    'aShape.Cells("Prop.Slot").Formula = """" & "J" & """"
    Debug.Print "Almost Done"

    MsgBox "Completed"
End Sub


it's odd, because the master shape is put in the page, so I though that line of code was ok.

Paul Herber

If the shape is added to the page then that line of code is ok. Add a check that aShape has been set (i.e. non-nil).
Before you set the shape property see if you can do something simple with the shape, e.g. set a different X or Y coordinate. Getting the syntax correct with multiple " characters is notoriously difficult.
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

wapperdude

Out of curiosity, is the Set aPage line providing the desired value for aPage?

Wapperdude
Visio 2019 Pro

Yacine

not sure, but aShape is an object. A simple "=" won't work, use "set aShape =" instead.
Yacine

Paul Herber

Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/