Building an Orgchart using VB

D

Don

Hi everyone...

I am looking for the missing link here - I have build Orgcharts using Excel
input files, and I was quite capable of doing this using the Command Line
Method.

The only problem was that I was not able to set the template for the webpage
and also, there is no easy way to save as HTML.

I rewrote most of the code in VBA but I am not sure how to invoke the macro
that runs the orgchart wizard. I have set up the parameters, and all I need
is the command to execute the wizard, and pass the args. I am including the
code I have wrote, there is a section that needs to be created where the
application (wizard) is invoked.

Regards

Don

code:

Public Sub Create_Model()

Dim docObj As Visio.Document
Dim runObj As Visio.Document

' these settings are for the orgchart wizard.
Const orgCWiz As String = "ORGANIZATION_CHART_WIZARD"
Const SFILE As String = "/FILENAME=Model Vision\test file.xls"
Const HLINK As String = "/HYPERLINK-FIELD=Hyperlink"
Const CFLDS As String = "/CUSTOM-PROPERTY-FIELDS=Program,Business
Group,Record Count"
Const DFLDS As String = "/DISPLAY-FIELDS=Program,Business Group,Record
Count"
Const NmFLD As String = "/NAME-FIELD=Model"

' these settings are for saving the file as HTML - change the name of the
file below in targetpath

Dim saveAsWeb As IVisSaveAsWeb
Dim webSettings As IVisWebPageSettings
Set saveAsWeb = New VisSaveAsWeb
Set webSettings = saveAsWeb.WebPageSettings

webSettings.StartPage = 1
webSettings.EndPage = 2
webSettings.LongFileNames = True
webSettings.SilentMode = True

'Open a new document based on a template.
Set docObj = Documents.Add _
("c:\Program Files\Microsoft Office\Visio10\1033\Solutions\Organization
Chart\Model Vision.vst")

'run the org chart wizard.
'
' !!!!!!!!!!!! help is needed here !!!!!!!!!


' save the file
webSettings.TargetPath = "c:\Model Vision\m10279.htm"
saveAsWeb.CreatePages
End Sub
 
A

Al Edlund

this from visio help (search on orgwiz.exe)

al

You can also run the Organization Chart Wizard from a program using the Run
method. You can use the following sample code as a guideline:

Private Const MAX_ARGSTRING_LENGTH% = 100

Sub Main()

'Read the command line
Dim strCommand As String
strCommand = Command$

'Check if the add-on exists
On Error GoTo OrgDoItErrHandler
Dim objVisio As Object
Set objAddOn As Object

Set objVisio = CreateObject("Visio.Application")
Set objAddOn = objVisio.Addons.ItemU("OrgCWiz")

'Run the add-on (errors are handled by the add-on)
On Error Resume Next

'Break up the string
Dim strCommandPart As String
Dim strCommandLeft As String
strCommandLeft = strCommand
objAddOn.Run ("/S-INIT")
While (Len(strCommandLeft) > 0)
strCommandPart = Left(strCommandLeft, MAX_ARGSTRING_LENGTH)
strCommandLeft = Mid(strCommandLeft, Len(strCommandPart) + 1)
objAddOn.Run ("/S-ARGSTR " + strCommandPart)
Wend
objAddOn.Run ("/S-RUN " + strCommandLeft)

Exit Sub

OrgDoItErrHandler:

End Sub
 
D

Don

Hi Al:

I'm sorry, but I already had it working using that method, the main problem
is that it opens a new copy of Visio, and I want to simply run the macro over
the existing worksheet. I have already set the background and template,
therefore, I just want to execute the macro (orgwiz) to import the data, and
to create the hierarchy

Thanks for the tip though

Regards

Don
 
A

Al Edlund

Since most 'org charts' are a very close relationship to building a standard
flowchart (merely nodes and connections), you might consider investigating
the code in the SDK which has an example of creating a flowchart.

Regarding your present project you might consider letting the org chart
create your drawing and then apply the background and other template objects
after it gets done.

al
 
D

Don

Thanks Al, that is great advice, I kind of got turned that direction myself.
I went out and bought 2003 visio last night - it cost 211.00, but my company
will pay for it. I should have got the upgrade however.

I have one remaining question: How do I set the background color or color
scheme to Primary ? I can do it using the manual save as web process, but I
am not sure what the code is to do it in VB.

I appreciate all the assistance, this is a great forum.

Regards
Don
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top