Creating VBA Textbox

Started by OldSchool1948, November 21, 2019, 01:26:29 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

OldSchool1948

Is it possible to create a Textbox object on a Visio page using VBA code?

Nikolay

You can try macro recroder. Start recording, insert the Textbox and see what the recorder produced. For me it produced the following:

Application.ActiveWindow.Page.InsertObject "{8BD21D10-EC42-11CE-9E0D-00AA006002F3}", visInsertAsControl + visInsertNoDesignModeTransition

OldSchool1948

#2
Thanks!.  This is what I came up with

Sub cre8TextBox()

    Application.EventsEnabled = False

    Dim vsoPage As Visio.Page
    Set vsoPage = Visio.ActivePage
   
    '// Create TextBox
    Dim oTB As Object
    Set oTB = vsoPage.InsertObject("{8BD21D10-EC42-11CE-9E0D-00AA006002F3}", visInsertAsControl + visInsertNoDesignModeTransition)
   
    With oTB
   
        .Object.Name = "tbRFCNumber"
        .Object.Text = "RFC-yyyy-####"
   
    End With
   
    '// Position and Format TextBox
    If Not oTB Is Nothing Then
   
        Dim vsoShape As Visio.Shape
        Set vsoShape = oTB
       
        vsoShape.Cells("Width").formula = "=1.625 in."
        vsoShape.Cells("Height").formula = "=0.375 in."
        vsoShape.Cells("PinX").formula = "=11.75 in."
        vsoShape.Cells("PinY").formula = "=10 in."
       
        vsoShape.CellsSRC(visSectionCharacter, visRowFirst, visCharacterSize).formula = "=12 pt"
        vsoShape.CellsSRC(visSectionCharacter, visRowFirst, visCharacterFont).formula = "=21"
       
    End If
   
    Application.EventsEnabled = True
   
    Set oTB = Nothing
   
End Sub


Paul Herber

Unless you mean just a simple text box, which is just a simple rectangle with LinePattern set to =THEMEGUARD(0)
Electronic and Electrical engineering, business and software stencils for Visio -

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