Visio Guy

Visio Discussions => Programming & Code => Topic started by: ddj on January 12, 2018, 01:19:37 PM

Title: adding text transform section from excell macro
Post by: ddj on January 12, 2018, 01:19:37 PM
Hi,
Would anyone know how to add a section from a macro that runs from an excell spreadsheet?
Been searching all over the place without much luck...

Basicly I can access whats there , but can't seem to figure out on how to add a section.
Any help would be greatly appriciated.

    Dim appVisio As Object
    Dim vsoShape As Object

    Set appVisio = CreateObject("visio.application")
     
    appVisio.Documents.AddEx "", visMSUS, 0
    appVisio.Visible = True
   

        Set vsoShape = appVisio.ActivePage.DrawRectangle1,4,4,1)
   
        vsoShape.Cells("FillForegndTrans") = 1     
        vsoShape.Cells("Char.Size").Result("pt") = 50
        vsoShape.Text = world(9, i)
Title: Re: adding text transform section from excell macro
Post by: Surrogate on January 12, 2018, 02:02:05 PM
Quote from: ddj on January 12, 2018, 01:19:37 PM
    Dim appVisio As Object
    Dim vsoShape As Object

    Set appVisio = CreateObject("visio.application")
     
    appVisio.Documents.AddEx "", visMSUS, 0
    appVisio.Visible = True
   

        Set vsoShape = appVisio.ActivePage.DrawRectangle1,4,4,1)
' there lose (
   
        vsoShape.Cells("FillForegndTrans") = 1     
        vsoShape.Cells("Char.Size").Result("pt") = 50
        vsoShape.Text = world(9, i)
' if variable i don't define, it mean that variable's value equal 0, and you get error

check my comments. this code works
Sub ddj()
    Dim appVisio As Object
    Dim vsoShape As Object
    Set appVisio = CreateObject("visio.application")
    appVisio.Documents.AddEx "", visMSUS, 0
    appVisio.Visible = True
    Set vsoShape = appVisio.ActivePage.DrawRectangle(1, 4, 4, 1)
    vsoShape.Cells("FillForegndTrans") = 1
    vsoShape.Cells("Char.Size").Result("pt") = 50
    vsoShape.Text = Cells(9, 1)
End Sub


Title: Re: adding text transform section from excell macro
Post by: ddj on January 12, 2018, 03:18:30 PM
Sorry, that was a sloppy "copy-paste-and-get-rid-of-unneccesary-stuff" from my part from a bigger routine the code actualy worked,

but what I can't figure out is how to add the section "transform text" to the shapesheet of the shape.
(trying to get the text above the shape and scale smaller when it's larger then the shape lenght)

I tried recording a macro in visio but what comes up there doesn't quite work from an excell macro, maybe I'm missing a reference?
Title: Re: adding text transform section from excell macro
Post by: wapperdude on January 12, 2018, 04:51:01 PM
Not at my computer are the moment, but since you're doing this from Excel, you need to make sure VBA has / access to Visio object model.  Anyway, it's starting point.

From this post,   http://visguy.com/vgforum/index.php?topic=7450.0
there's this note: 
' The following references are used:
'   Visual Basic for Applications
'   Microsoft Visio Type Library
'   OLE Automation
'   Microsoft Office Object Library
'   Microsoft Excel Object Library
'   You'll have to choose the appropriate versions based upon your installation

Wapperdude
Title: Re: adding text transform section from excell macro
Post by: sockmonkeyrevolt on January 12, 2018, 05:17:54 PM
If I'm reading you right, you are getting it to create the rectangle shape you just want to add the Text Transform section to the shape sheet

I think it should be


vsoShape.AddRow visSectionObject, visRowTextXForm, visTagDefault



I'm just in visio right now, but that added that section to a shape I didn't have it in. TextTransform doesn't seem to be an enumerated section that you can use the AddSection method to add, seems like it has to be added by adding a row.
Title: Re: adding text transform section from excell macro
Post by: ddj on January 12, 2018, 05:53:49 PM
@sockmonkeyrevolt  Yup, exactly, And I had that part figured out but it kept trowing me errors, I was totaly clueless about why until....

@wapperdude You are my new hero !! Apperantly all i needed to do was add the
Microsoft Visio Type Library *rolls eyes*
I feel so stupid now after hours of searching how or why.

Anyway, now that I have that sorted, should I keep these all as object or go to the actual type?

"Dim vsoShape As Object"
or go for
"Dim vsoShape As Visio.Shape".
Title: Re: adding text transform section from excell macro
Post by: wapperdude on January 12, 2018, 07:41:28 PM
Use the 2nd...no confusion that way.