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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating a WORD document

Status
Not open for further replies.

Gorkem

Programmer
Jun 18, 2002
259
CA
Hi All,

ok.. here is my problem.. I have a word document that I am updating from my website. The user enter's values into a form and submits it for processing by the server. The server opens the word document locally on the server, makes the changes, saves and returns. So far everything works great.. Here is my problem.

There is a graph (chart) in my word document that I want to update as well.. Does anyone have any idea how to obtain the chart object inside the document? I know there must be a way because the MSWORD Object Library exposes all the functions. I think I am just overlooking something.. Any help would be appreciated.

Cheers,

Gorkem.
 
Ok.. I figured it out.. I will post my code below incase anyone else runs into this problem..

<%
Set wordapp = server.createobject(&quot;Word.Application&quot;)
Set WordDoc = server.createobject(&quot;Word.Document&quot;)
Set WordGraph = server.createobject(&quot;Word.Shape&quot;)

' Open an existing document
'Set WordDoc = wordapp.Documents.Open(&quot;C:\documents\reporttest.doc&quot;)
' Create a new document.
Set WordDoc = wordapp.Documents.Add

WordDoc.Paragraphs.Add
WordDoc.Paragraphs.Alignment = wdAlignParagraphCenter
WordDoc.Bookmarks.Add &quot;CHART2&quot;, WordDoc.Paragraphs(1).Range

' Add the Chart object to our document
Set wordgraph = WordDoc.Shapes.AddOLEObject(ClassType:=&quot;MSGraph.Chart.8&quot;, Anchor:=WordDoc.Bookmarks.Item(&quot;CHART2&quot;).Range)

' Obtain the chart object to work with..
Set oChart = wordgraph.OLEFormat.object
wordgraph.OLEFormat.Label = &quot;Revenue&quot;
With oChart
.ChartType = xl3DPieExploded
.HasTitle = True
.Application.DataSheet.Cells.Delete

.Application.DataSheet.Cells(1, 2).Value = &quot;SALES&quot;
.Application.DataSheet.Cells(1, 3).Value = &quot;COMMISSION&quot;
.Application.DataSheet.Cells(1, 4).Value = &quot;TOTAL REVENUE&quot;
.Application.DataSheet.Cells(2, 2).Value = &quot;20%&quot;
.Application.DataSheet.Cells(2, 3).Value = &quot;30%&quot;
.Application.DataSheet.Cells(2, 4).Value = &quot;50%&quot;
.Application.Chart.Elevation = 45
.Application.Chart.Rotation = 45
.Application.Chart.Legend.Font.Size = 8
.Application.Chart.Legend.Font.Bold = False
.Application.Chart.PlotArea.Fill.Visible = msoFalse
.Application.Chart.PlotArea.Border.Color = RGB(255, 255, 255)
.Application.Chart.ApplyDataLabels 3
.Application.Chart.ChartArea.Font.Bold = False
.Application.Chart.ChartArea.Font.Size = 8
.ChartTitle.Caption = &quot;GORKEMS TEST&quot;
.ChartTitle.Font.Shadow = True
.ChartTitle.Font.Size = 14
.ChartTitle.Font.Bold = True
.Application.Chart.Pie3DGroup.HasRadarAxisLabels = True
End With

' Password protect our document and save
WordDoc.Protect wdAllowOnlyComments, True, &quot;testpassword&quot;
WordDoc.SaveAs (&quot;REPORTTEST.DOC&quot;)
wordapp.Quit (False)

' Clean up
set wordapp = nothing
set worddoc = nothing
set wordgraph = nothing
set ochart = nothing
%>


I hope this will be of use to others as well.

Cheers,

Gorkem.
 
Sorry everyone.. there is a correction..

Remove the line:

wordgraph.OLEFormat.Label = &quot;Revenue&quot;

This was something else I was testing.. forgot to take it out..


Cheers,

Gorkem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top