Howto: automate Visio by using VC++

L

Lars

Hi all,

I try to implement the following very simple steps by
automation using VC++:

1. Start MS Visio 2000
2. Open a csv or txt-file
3. Save the file as a Visio drawing (vsd)
4. Exit Visio

....during I perform these steps manually there were
absolutly no problems. Even if I opened a vsd-file via
automation there were no problems at all. But every time I
try to open a csv-file by automation, I get a
COleException from Visio and I will not be able to save
the file or perform any other automation-steps. I will be
very glad if anybody could help me in this case. Please
have a look on my source-code below which works fine for
opening vsd-files:


void CVisioAutomationDlg::OnButton1()
{
IVApplication app;
IVDocuments docs;
IVDocument doc;

if (app.CreateDispatch("Visio.Application"))
{
docs = app.GetDocuments();
if (docs)
{
doc = docs.Open("D:\\My Data\\Data\\Ablauf.csv");
// doc = docs.Open("D:\\My Data\\Data\\Ablauf.vsd");
doc.SaveAs("D:\\My Data\\Data\\Ablauf_neu.vsd");
app.Quit();
}
}
}

Thanks a lot

Regards, Lars
 
C

Chris Roth [ Visio MVP ]

You might try the OpenEx or Import methods.

They removed the CSV import from 2003, so I can't readily test it right now.

Also, try searching the Add-ons collection (Visio.Application.Addons) and
see if anything suspicious shows up. I believe the CSV import function began
life as an add-on, and it may be that the Open File dialog rerouts .CSV file
selections to this add-on.

--

Hope this helps,

Chris Roth
Visio MVP
 
L

Lars

Hi Chris,

thanks for your answer!

I already tried the OpenEx-method with different values
listed under "VisOpenSaveArgs" in visio.tlh. but it didn't
work. What about the Import-method? I can't find it in the
IVDocument(s) or IVApplication classes.

The add-on strategy sounds interesting: where can I find
them and how will this work? I'm a newbie in this case,
because I havn't worked with these things before.

Thanks in advance,

Lars
 
C

Chris Roth [ Visio MVP ]

To get a list of add-ons, run this in VBA:

Sub ListAddOns()

Dim i As Integer

For i = 1 To Visio.Application.Addons.Count

Debug.Print Visio.Application.Addons(i).Name,
Visio.Application.Addons(i).NameU

Next i

End Sub



For Visio 2003, I get the following. You will have different results for
older versions.



Aec Aec

AutoSpaceConvert AutoSpaceConvert

AutoSpaceDrop AutoSpaceDrop

AutoSpaceResize AutoSpaceResize

Move Shapes... Move Shapes...

Shape Area and Perimeter... Shape Area and Perimeter...

Array Shapes... Array Shapes...

Measure Tool Measure Tool

Brainstorming BRAINSTORM

DB Engineer DB Engineer

Database Wizard DBWiz

Database Re-Export DBREX

DBEXP DBEXP

Link to Database... DBLINK

Database Refresh DBRS

Database Select Record DBS

Database Refresh Shape DBR

Database Update Record DBU

Database Update DBUS

Database Delete Shape DBD

Database Launch Monitor DBL

Database Settings... DBO

Database Export Wizard DBEX

Open AutoCAD Drawing Open AutoCAD Drawing

DumpDwgDp DumpDwgDp

CnvtDwgDp CnvtDwgDp

Convert CAD Library... Convert AutoCAD Library

Convert CAD Drawings... Convert AutoCAD Drawings

Export to AutoCAD DXF Export to AutoCAD DXF

Export to AutoCAD Export to AutoCAD DWG

Insert AutoCAD Drawing Insert AutoCAD Drawing

DwgCropTool DwgCropTool

Event Monitor... EVTMON

Facilities Event Model FMmodel

Install Printer FMprint

Label Shapes FMlabel

Facilities New Drawing Wizard FMstart

Color by Values FMcolor

Disable Space Plan FMdisable

Enable Space Plan FMenable

Refresh Data FMrefresh

Import Data FMimport

Assign Category FMcats

Gantt Chart GC

Visio Project Scheduler Visio Project Scheduler

Import Project Data Wizard GCIMP

Export Project Data Wizard GCEXP

Hvac Hvac

Legend lgnd

Organization Chart OrgC11

Organization Chart Converter OrgC

orgwiz.exe orgwiz.exe

Organization Chart Wizard OrgCWiz

PESolution PESolution

projimpt.exe projimpt.exe

Reports... VisRpt

Persist Events... PEVTS

SaveAsWeb SaveAsWeb

Number Shapes... SN

Update Shapes... Update Shapes...

Print ShapeSheet... PSS

&Standard Shape Tests SSTSTD

&Custom Shape Tests SSTCUS

&Find and Replace SSTFR

S&et Cells SSTSC

&Geometry Driven by Control Handle Tool SSCTRLHANDLE

S&hape Structure Tool SSStruct

&Multistate Tool SSMState

ShapeStudio SStd

Time Solution ts

tl tl

_Timeline.exe _Timeline.exe

tlimpt.exe tlimpt.exe

UML Background Add-on UML Background Add-on

Make Background Make Background

Color Schemes CS

Powerpointize PPT

Color Schemes... Color Schemes...

BR BR

Organization Chart Wizard.exe Organization Chart Wizard.exe

Project Timeline Project Timeline

Project Timeline Wizard.exe Project Timeline Wizard.exe

Organization Chart 98 Wizard.exe Organization Chart 98 Wizard.exe

Organization Chart 98 Wizard Organization Chart 98 Wizard

Organization Chart 98 Converter Organization Chart 98 Converter

OrgCWiz HeadTrax OrgCWiz

Simple Timeline.exe Simple Timeline.exe

SUBMAKER.EXE SUBMAKER.EXE

Link To Page Link To Page

cc cc

Link To Document Link To Document

Make Department Make Department

Make Web Make Web

OPC OPC

QueueMarkerEvent QueueMarkerEvent

Network Shape Properties Network Shape Properties

cpm cpm

REGION.EXE REGION.EXE

Build Region.EXE BuildRegion.EXE

ORGWIZRD.EXE ORGWIZRD.EXE

REPORTER.EXE REPORTER.EXE

SSPRINT.EXE SSPRINT.EXE

TIMELINE.EXE TIMELINE.EXE

Print ShapeSheet.exe Print ShapeSheet.exe

Web Site Map VisWeb

Cross Functional CFF

Rummler-Brache Add-on Rummler-Brache Add-on


--

Hope this helps,

Chris Roth
Visio MVP
 

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