Text Font Size

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • joemo2003
    New Member
    • Feb 2007
    • 142

    #1

    Text Font Size

    How to change the textbox text size in visio using vb6? is something like the follow? but it seem not work, anybody help?

    Dim ashape As Shape
    ashape.Text.Fon t = New Font("Times New Roman", 22)
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Try this:
    Code:
    ashape.Text.Font.Size = 22

    Comment

    • vijaydiwakar
      Contributor
      • Feb 2007
      • 579

      #3
      Originally posted by joemo2003
      How to change the textbox text size in visio using vb6? is something like the follow? but it seem not work, anybody help?

      Dim ashape As Shape
      ashape.Text.Fon t = New Font("Times New Roman", 22)
      u've given the code related to .net
      in vb6 use font. property name
      Last edited by Killer42; Mar 6 '07, 08:10 AM. Reason: Add version number to 'vb' for clarification

      Comment

      • joemo2003
        New Member
        • Feb 2007
        • 142

        #4
        Originally posted by Killer42
        Try this:
        Code:
        ashape.Text.Font.Size = 22

        "ashape.Text=xx x" do output "xxx" to my visio drawing with default text size of 12, but when i try "ashape.Text.Fo nt.Size=22", it selected the "Text" and come out "compile error invalid qualifier". Do any one know what is happening?

        Thanks

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by joemo2003
          "ashape.Text=xx x" do output "xxx" to my visio drawing with default text size of 12, but when i try "ashape.Text.Fo nt.Size=22", it selected the "Text" and come out "compile error invalid qualifier". Do any one know what is happening?
          Try leaving out "Text". That is, ashape.Font.Siz e=22.

          Comment

          • joemo2003
            New Member
            • Feb 2007
            • 142

            #6
            Originally posted by Killer42
            Try leaving out "Text". That is, ashape.Font.Siz e=22.
            Same error message with "ashape" got selected. Do you know when that will happen?

            thanks much

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Originally posted by joemo2003
              Same error message with "ashape" got selected. Do you know when that will happen?
              Are you sure that ashape exists? What type is it?

              Comment

              • joemo2003
                New Member
                • Feb 2007
                • 142

                #8
                Originally posted by Killer42
                Are you sure that ashape exists? What type is it?
                Here is my basic code:
                Dim adoc As Document, amaster As Master
                Dim apage As Page, ashape As Shape
                Set apage = ActivePage
                Set adoc = Documents("basi c shapes.vss")
                'draw a rectangle textbox to visio
                Set amaster = adoc.Masters("r ectangle")
                'set the textbox's location
                Set ashape = apage.Drop(amas ter, 3, 4)
                ashape.Text =XXX
                ashape.Text.Fon t.size=22

                everything except the font size work fine, any ideal?

                Thanks

                Comment

                • Killer42
                  Recognized Expert Expert
                  • Oct 2006
                  • 8429

                  #9
                  In VB6, the Shape object does not have a Font property. Or a Text property. I don't get it. Do the Visio objects somehow replace the built-in ones?

                  Comment

                  • SammyB
                    Recognized Expert Contributor
                    • Mar 2007
                    • 807

                    #10
                    I don't have Visio on any of my current computers, but I think you have to create a Cell and then change the font. Something like
                    Dim ashape As Visio.Shape ' Always qualify your Visio variables
                    Dim vsoCell As Visio.Cell
                    Set vsoCell = ashape.Cells("C har.Size")
                    vsoCell.Formula = "=22 pt."
                    Nothing is easy in Visio! HTH --Sam

                    Originally posted by joemo2003
                    Here is my basic code:
                    Dim adoc As Document, amaster As Master
                    Dim apage As Page, ashape As Shape
                    Set apage = ActivePage
                    Set adoc = Documents("basi c shapes.vss")
                    'draw a rectangle textbox to visio
                    Set amaster = adoc.Masters("r ectangle")
                    'set the textbox's location
                    Set ashape = apage.Drop(amas ter, 3, 4)
                    ashape.Text =XXX
                    ashape.Text.Fon t.size=22

                    everything except the font size work fine, any ideal?

                    Thanks

                    Comment

                    • SammyB
                      Recognized Expert Contributor
                      • Mar 2007
                      • 807

                      #11
                      Found a Visio machine, but VB6 is long gone, so I faked it with Excel VBA. Here's what it should look like:
                      Code:
                      Option Explicit
                      Private vsApp As Visio.Application
                      
                      Sub BtnStart_Click()
                          Dim vsDoc As Visio.Document
                          Set vsApp = CreateObject("Visio.Application")
                          Set vsDoc = vsApp.Documents.Add("basic shapes.vss")
                      End Sub
                      
                      Sub BtnDrop_Click()
                          Dim vsDoc As Visio.Document
                          Dim vsMaster As Visio.Master
                          Dim vsPage As Visio.Page
                          Dim vsShape As Visio.Shape
                          Dim vsCell As Visio.Cell
                          Set vsDoc = vsApp.ActiveDocument
                          Set vsPage = vsDoc.Pages(1)
                          vsPage.OpenDrawWindow
                          vsApp.Windows.Arrange visArrangeTileVertical
                          Set vsMaster = vsDoc.Masters("rectangle")
                          Set vsShape = vsPage.Drop(vsMaster, 3, 4)
                          vsShape.Text = "Hi!"
                          Set vsCell = vsShape.Cells("Char.Size")
                          vsCell.Formula = "=22 pt."
                          Set vsCell = Nothing
                          Set vsShape = Nothing
                          Set vsPage = Nothing
                          Set vsMaster = Nothing
                      End Sub
                      
                      Sub BtnClose_Click()
                          Dim vsDoc As Visio.Document
                          Set vsDoc = vsApp.ActiveDocument
                          vsDoc.SaveAs "MyTestVisioDoc.vsd"
                          vsApp.Quit
                          Set vsDoc = Nothing
                          Set vsApp = Nothing
                      End Sub

                      Comment

                      • joemo2003
                        New Member
                        • Feb 2007
                        • 142

                        #12
                        Originally posted by Killer42
                        In VB6, the Shape object does not have a Font property. Or a Text property. I don't get it. Do the Visio objects somehow replace the built-in ones?
                        I am not sure, but it work.

                        Comment

                        • joemo2003
                          New Member
                          • Feb 2007
                          • 142

                          #13
                          Originally posted by SammyB
                          Found a Visio machine, but VB6 is long gone, so I faked it with Excel VBA. Here's what it should look like:
                          Code:
                          Option Explicit
                          Private vsApp As Visio.Application
                          
                          Sub BtnStart_Click()
                              Dim vsDoc As Visio.Document
                              Set vsApp = CreateObject("Visio.Application")
                              Set vsDoc = vsApp.Documents.Add("basic shapes.vss")
                          End Sub
                          
                          Sub BtnDrop_Click()
                              Dim vsDoc As Visio.Document
                              Dim vsMaster As Visio.Master
                              Dim vsPage As Visio.Page
                              Dim vsShape As Visio.Shape
                              Dim vsCell As Visio.Cell
                              Set vsDoc = vsApp.ActiveDocument
                              Set vsPage = vsDoc.Pages(1)
                              vsPage.OpenDrawWindow
                              vsApp.Windows.Arrange visArrangeTileVertical
                              Set vsMaster = vsDoc.Masters("rectangle")
                              Set vsShape = vsPage.Drop(vsMaster, 3, 4)
                              vsShape.Text = "Hi!"
                              Set vsCell = vsShape.Cells("Char.Size")
                              vsCell.Formula = "=22 pt."
                              Set vsCell = Nothing
                              Set vsShape = Nothing
                              Set vsPage = Nothing
                              Set vsMaster = Nothing
                          End Sub
                          
                          Sub BtnClose_Click()
                              Dim vsDoc As Visio.Document
                              Set vsDoc = vsApp.ActiveDocument
                              vsDoc.SaveAs "MyTestVisioDoc.vsd"
                              vsApp.Quit
                              Set vsDoc = Nothing
                              Set vsApp = Nothing
                          End Sub

                          Thanks, all i need is add the follow to my code.
                          Set vsCell = vsShape.Cells(" Char.Size")
                          vsCell.Formula = "=22 pt."

                          Comment

                          • SammyB
                            Recognized Expert Contributor
                            • Mar 2007
                            • 807

                            #14
                            Originally posted by joemo2003
                            Thanks, all i need is add the follow to my code.
                            Set vsCell = vsShape.Cells(" Char.Size")
                            vsCell.Formula = "=22 pt."
                            Visio must be very forgiving! Notice that you get the page before you get the document. Also, most of Object Libraries have Application, Document and Shape objects so you really need to prefix you declarations with Visio. Speaking from experience, VB lets you get away with way too much sloppy code.

                            Comment

                            • joemo2003
                              New Member
                              • Feb 2007
                              • 142

                              #15
                              Originally posted by SammyB
                              Visio must be very forgiving! Notice that you get the page before you get the document. Also, most of Object Libraries have Application, Document and Shape objects so you really need to prefix you declarations with Visio. Speaking from experience, VB lets you get away with way too much sloppy code.

                              Seem you know Visio a lot. can you help me on one more thing? I try to create a commandbuttom1 in visio VBA, when i click that buttom it will open the Opendialog box to browse and open a excel file, that Opened excel file name will use as "XXX" in the code below. And when i click the commandbutton2 it will inport the excel data in visio. What i don't get is how to write the code for commandbutton1. In excel VBA we can use "Application.Di alogs(xldialogo pen).Show", and in visio I find something "MsoOpenfil e". Can you help me how to use it?


                              Private Sub CommandButton1_ Click()
                              ???
                              'need to open a excel file.
                              End Sub

                              Private Sub CommandButton2_ Click()
                              Dim xlObjApp As Excel.Applicati on
                              Dim xlObjBook As Excel.Workbook
                              Dim xlObjSheet As Excel.Worksheet
                              Set xlObjApp = GetObject(, "Excel.Applicat ion")
                              Set xlObjBook = xlObjApp.Workbo oks.Item("XXX.x ls")
                              Set xlObjSheet = xlObjBook.Works heets.Item("She et1")
                              TextBox1 = xlObjSheet.Cell s(1, 1)

                              Comment

                              Working...