Author Topic: Creating VBA Textbox  (Read 1526 times)

0 Members and 1 Guest are viewing this topic.

OldSchool1948

  • Jr. Member
  • **
  • Posts: 50
Creating VBA Textbox
« on: November 21, 2019, 08:26:29 AM »
Is it possible to create a Textbox object on a Visio page using VBA code?

Nikolay

  • Hero Member
  • *****
  • Posts: 835
    • UnmanagedVisio
Re: Creating VBA Textbox
« Reply #1 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

OldSchool1948

  • Jr. Member
  • **
  • Posts: 50
Re: Creating VBA Textbox
« Reply #2 on: November 21, 2019, 03:53:39 PM »
Thanks!.  This is what I came up with

Code: [Select]
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
« Last Edit: November 22, 2019, 07:44:14 AM by OldSchool1948 »

Paul Herber

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2823
    • Paul Herber's website
Re: Creating VBA Textbox
« Reply #3 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)
Electronic and Electrical engineering, business and software stencils and applications for Visio -

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