Programmatically creating charts with Word and VB.Net

P

paul

Hi to all!

I have an issue that has been bugging me for quite some time and I hope that
someone might be able to point me into the right direction here.

The story is – I am writing an application that would allow a user to create
a Word output from pre-defined data tables. The output can contain both
charts and tables. While generating the output, Word or MSGraph cannot be
visible to the user. What I have is something like this

Code:
private sub AddChart(params)

Dim oShape As Word.InlineShape
Dim oChart As Object

oShape =
_wordDocument.Bookmarks.Item("\endofdoc").Range.InlineShapes.AddOLEObject(ClassType:="MSGraph.Chart.8",
FileName:="", LinkToFile:=False, DisplayAsIcon:=False)

oChart = oShape.OLEFormat.Object

If (chartOptions.UpdateDataSheet(oChart) <> True) Then
CLogger.Log("Chart has no data present.  Check to make sure you
are not hidding the entire chart", CLogger.EntryType.Warning)
End If

CLogger.LogIf("Updating Chart Options")
chartOptions.UpdateChart(oChart)


oChart.Application.Update()
oChart.Application.Quit()
AddSection()
End sub

Here is what happens – first time we run this – everything is good, second
time, Word document becomes visible as well as the MSGraph window appears.
It happens when we hit the line with oShape = …….

I am wondering if someone knows the way to hide that Word document and that
MSGraph window.

Thanks in advance.
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?cGF1bA==?=,

I'm afraid it's not possible, at least, not that I've ever been able to work
out. You can try adding a Set oChart = Nothing after the .Quit command. And
maybe a DoEvents or Sleep to give things time to catch up. But in my experience,
the two applications in concert NEED to layout on-screen in order to function
properly.

I'm pretty sure you'd run into the same problem if you tried this with Excel
charts, instead.

About the only thing I can imagine could work "invisibly" would be to create all
the charts in separate Excel workbooks, then insert them as LINK field codes
into the document. Then break the links to embed them as graphics.
I have an issue that has been bugging me for quite some time and I hope that
someone might be able to point me into the right direction here.

The story is – I am writing an application that would allow a user to create
a Word output from pre-defined data tables. The output can contain both
charts and tables. While generating the output, Word or MSGraph cannot be
visible to the user. What I have is something like this

Code:
private sub AddChart(params)

Dim oShape As Word.InlineShape
Dim oChart As Object

oShape =
 _wordDocument.Bookmarks.Item("\endofdoc").Range.InlineShapes.AddOLEObject(ClassT
ype:="MSGraph.Chart.8",
FileName:="", LinkToFile:=False, DisplayAsIcon:=False)

oChart = oShape.OLEFormat.Object

If (chartOptions.UpdateDataSheet(oChart) <> True) Then
CLogger.Log("Chart has no data present.  Check to make sure you
are not hidding the entire chart", CLogger.EntryType.Warning)
End If

CLogger.LogIf("Updating Chart Options")
chartOptions.UpdateChart(oChart)


oChart.Application.Update()
oChart.Application.Quit()
AddSection()
End sub

Here is what happens – first time we run this – everything is good, second
time, Word document becomes visible as well as the MSGraph window appears.
It happens when we hit the line with oShape = …….

I am wondering if someone knows the way to hide that Word document and that
MSGraph window.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

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