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
>
>