Visio Guy

Visio Discussions => Programming & Code => Topic started by: OldSchool1948 on November 21, 2019, 08:26:29 AM

Title: Creating VBA Textbox
Post by: OldSchool1948 on November 21, 2019, 08:26:29 AM
Is it possible to create a Textbox object on a Visio page using VBA code?
Title: Re: Creating VBA Textbox
Post by: Nikolay on November 21, 2019, 08:49:01 AM
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
Title: Re: Creating VBA Textbox
Post by: OldSchool1948 on November 21, 2019, 03:53:39 PM
Thanks!.  This is what I came up with

Code
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
Title: Re: Creating VBA Textbox
Post by: Paul Herber on November 22, 2019, 04:27:19 AM
Unless you mean just a simple text box, which is just a simple rectangle with LinePattern set to =THEMEGUARD(0)