Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can you Automate a Word Chart from VB6? 1

Status
Not open for further replies.

pgstein

Programmer
Jul 27, 2005
33
US
Hello,
I am currently using VB6 to automate word and generate a report. I use vb6 to open a report template that I have made, and then fill in the correct data (using bookmarks).
The problem I am having is that the document contains a chart that I need to modify, and I have no idea how to do it. Doing it from word is easy, just right click on the chart, goto "datasheet", and type in the correct values. Does anyone have any idea on how to do this from visual basic?
Some of my code is pasted below.
Any responses would be greatly appreciated. Thanks
Paul


Dim wordapp As Word.Application
Dim doc As Document

Set wordapp = CreateObject("Word.Application")
Set doc = wordapp.Documents.Add("Report_Test")

'this is how I enter my data
With wordapp
.ActiveDocument.Bookmarks("bmCustomer").Select
.Selection.TypeText (Customer)
End With

Thanks again!
 
I don't work with VBA too much, but what I do in situations where something is doable in Word or Excel and not VB, is I record a macro, capturing my actions as I do what I wish to do through code. Then I grab the code, rework it and leave it in the document if I can, as a function, or paste the code in VB and alter it to fit. I'm not sure if it will work in your case but it's worth a shot.
-Max
 
I have tried that, but when I go to record the macro in Word, it wont let me click on anything (including the chart). Is this normal? or maybe something is wrong with my settings?
 
Have you tried linking the chart to a file and just changing the contents of the file somehow?
-Max
 
No i haven't. That is actually not a bad idea though. You wouldnt happen to know if you could change the name of the linked file from vb, that would solve the problem completely.
 
acutally, do you know how to link a chart to a file in general? ive tried but have no clue. thanks.
 
I can't try anything right now, so I don't know if it will work. But try accessing the chart's properties through vb - there's gotta be a way. Sorry I can't be more helpful.
-Max
 
Hi, depending on where does the chart come from (excel, MSChart) and what is his position (Shape, InlineShape), the solution differs. Below, after referencing Microsoft Word and Microsoft Graph object libraeies with wdDoc word document variable, and InlineShape/Chart configuration:

Dim graGraph As Graph.Chart
wdDoc.InlineShapes(1).Activate
Set graGraph = Me.InlineShapes(1).OLEFormat.Object
With graGraph.Application
.DataSheet.Cells(2, 2) = 15
.Quit
End With

After referencing given office application library, you can browse library in Object browser and access help files.

combo
 
Thanks alot! works great. "When the world is mine, your death shall be quick and painless.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top