Hi,

Has anyone had any experience in scripting the organization chart in word or
Excel. I know the version in Office XP/2003 is an instance of the Shapes
object (as opposed to the org chart 2.0 in older versions) and I have a
working VBA macro to manipulate the chart taken from MSDN but I haven't been
able to find a VBscript to do the same thing.

Cheers,

TK

Re: Scripting the Word organization chart. by TDM

TDM
Wed Jan 04 15:04:48 CST 2006


"TK" <TK@noaddress.com> wrote in message
news:On0R09%23DGHA.2912@tk2msftngp13.phx.gbl...
> Hi,
>
> Has anyone had any experience in scripting the organization chart in word
> or
> Excel. I know the version in Office XP/2003 is an instance of the Shapes
> object (as opposed to the org chart 2.0 in older versions) and I have a
> working VBA macro to manipulate the chart taken from MSDN but I haven't
> been
> able to find a VBscript to do the same thing.
>
> Cheers,
>
> TK
>
>

TK,

I decided to take a quick look at this, might come in handy someday.
Here is what I came up with, might be at least a start for you.

Dim objOrgChart
Dim objWordApp
Dim objWordDoc
Dim objOrgChild
Dim objOrgAssistant
Dim objOrgRoot
Dim objNewNode
Dim iCtr
Dim iCtr2

Const msoDiagramOrgChart = 1
Const msoDiagramAssistant = 3
Const msoOrgChartLayoutRightHanging = 4

Set objWordApp = WScript.CreateObject("Word.Application")
Set objWordDoc = objWordApp.Documents.Add

objWordDoc.Application.Visible = True
objWordDoc.Application.ShowMe

With objWordDoc
Set objOrgChart = .Shapes.AddDiagram(msoDiagramOrgChart, 10, 15, 400, 475)
With objOrgChart
Set objOrgRoot = .DiagramNode.Children.AddNode
Call addOrgText(objOrgRoot, "Parent Node")
For iCtr = 1 to 3
objOrgRoot.Children.AddNode
Set objOrgChild = objOrgRoot.Children.Item(iCtr)
objOrgChild.Layout = msoOrgChartLayoutRightHanging
Call addOrgText(objOrgChild, "Child Node")
For iCtr2 = 1 to 3
objOrgChild.Children.AddNode(msoDiagramAssistant)
Set objOrgAssistant = objOrgChild.Children.Item(iCtr2)
Call addOrgText(objOrgAssistant, "Assistant Node")
Next
Next
End With
End With

Function addOrgText(objNode, strText)

With objNode.TextShape.TextFrame
With .TextRange
With .Font
.Bold = True
.Italic = True
.Name = "Arial"
.Size = 14
ENd With
.Text = strText & vbCrLf
End With
End With

End Function


TDM



Re: Scripting the Word organization chart. by TK

TK
Sun Jan 08 16:54:31 CST 2006

Thanks, this is exactly what I was looking for! I'm a casual scripter and
most of my work is for system admining (adminning?) but the script I'm
working on at the moment will let managers produce automatically produce org
charts for their areas using info pulled from the AD (at least that is the
idea, the auto formatted org charts aren't very nice when the chart is
complex). I'm offering this to the managers as an "ooh, pretty" feature as a
way of encouraging them to keep me up to date with the details of their
staff.

Is there a good reference for using Shapes object with VBscript? I've been
searching for a while without luck.

Cheers,

TK

"TDM" <tdm3@nospam.net> wrote in message
news:ezIaAKXEGHA.1312@TK2MSFTNGP09.phx.gbl...
>
> "TK" <TK@noaddress.com> wrote in message
> news:On0R09%23DGHA.2912@tk2msftngp13.phx.gbl...
> > Hi,
> >
> > Has anyone had any experience in scripting the organization chart in
word
> > or
> > Excel. I know the version in Office XP/2003 is an instance of the Shapes
> > object (as opposed to the org chart 2.0 in older versions) and I have a
> > working VBA macro to manipulate the chart taken from MSDN but I haven't
> > been
> > able to find a VBscript to do the same thing.
> >
> > Cheers,
> >
> > TK
> >
> >
>
> TK,
>
> I decided to take a quick look at this, might come in handy someday.
> Here is what I came up with, might be at least a start for you.
>
> Dim objOrgChart
> Dim objWordApp
> Dim objWordDoc
> Dim objOrgChild
> Dim objOrgAssistant
> Dim objOrgRoot
> Dim objNewNode
> Dim iCtr
> Dim iCtr2
>
> Const msoDiagramOrgChart = 1
> Const msoDiagramAssistant = 3
> Const msoOrgChartLayoutRightHanging = 4
>
> Set objWordApp = WScript.CreateObject("Word.Application")
> Set objWordDoc = objWordApp.Documents.Add
>
> objWordDoc.Application.Visible = True
> objWordDoc.Application.ShowMe
>
> With objWordDoc
> Set objOrgChart = .Shapes.AddDiagram(msoDiagramOrgChart, 10, 15, 400,
475)
> With objOrgChart
> Set objOrgRoot = .DiagramNode.Children.AddNode
> Call addOrgText(objOrgRoot, "Parent Node")
> For iCtr = 1 to 3
> objOrgRoot.Children.AddNode
> Set objOrgChild = objOrgRoot.Children.Item(iCtr)
> objOrgChild.Layout = msoOrgChartLayoutRightHanging
> Call addOrgText(objOrgChild, "Child Node")
> For iCtr2 = 1 to 3
> objOrgChild.Children.AddNode(msoDiagramAssistant)
> Set objOrgAssistant = objOrgChild.Children.Item(iCtr2)
> Call addOrgText(objOrgAssistant, "Assistant Node")
> Next
> Next
> End With
> End With
>
> Function addOrgText(objNode, strText)
>
> With objNode.TextShape.TextFrame
> With .TextRange
> With .Font
> .Bold = True
> .Italic = True
> .Name = "Arial"
> .Size = 14
> ENd With
> .Text = strText & vbCrLf
> End With
> End With
>
> End Function
>
>
> TDM
>
>



Re: Scripting the Word organization chart. by TDM

TDM
Sun Jan 08 18:39:48 CST 2006


"TK" <TK@noaddress.com> wrote in message
news:%23uCq2ZKFGHA.2040@TK2MSFTNGP14.phx.gbl...
> Is there a good reference for using Shapes object with VBscript? I've been
> searching for a while without luck.
>
> Cheers,
>
> TK

TK,

For the most part, I use MSDN, mostly on-line, but at home with my wimpy
dial up, I use the installed version. I may be off base here, but many
times, it
seems to me there is a lot of inconsistency and lack of an organized way to
find
the complete and concise Object Model definitions. Maybe it is out there
somewhere and I just aint found it yet, but it sure would be nice to be able
to
start at the top of the object model hierarchy. For the most part, I have
been
happy with the on-line MSDN from M$. That and google usually get me what
I need to know.

Sorry I dont have a better answer, but that is how I came up with the code
I posted. I did play around with other "shapes", but I left that code out.
If
you want me to post it, I can. One draw back to VBS versus VB is that
most Constants have to be declared, and for finding those constants, I use
the VB Object Browser. FYI.

TDM