Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Other Office > Word VBA
|
Word VBA Discuss using VBA to program Word.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Word VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 27th, 2009, 12:36 PM
Authorized User
 
Join Date: Jun 2003
Posts: 22
Thanks: 1
Thanked 0 Times in 0 Posts
Question Display/Update Picture Chart Dynamically in Word Using VBA

Hi all,

I am super green working with VBA (asp.net developer) and i have a project to complete where I have to update a Word chart with values obtained from a Stored Procedure (SP).

As my code stands, I have code that reads values from my SP and creates a table within Word. What i would like to do from there is create a chart just underneath the table with the values input from my table so as the values derived from the SP change, the Chart will change accordingly. Here is the code that I used to write out the table (again, I am new to VBA code so I am sure there is a better way of doing this):

Sub FillSelfEval()
Dim lst As Table
Set lst = ActiveDocument.Tables(1)
Dim intnum As Integer
intnum = 2
Dim chgVal As Integer
chgVal = 1
Dim rs As ADODB.Recordset
Dim db As Object
Set db = New ADODB.Connection
db.ConnectionString = "DSN=SelfEval; UID=""; PWD=''"
db.Mode = ADODB.ConnectModeEnum.adModeReadWrite
db.Open

ActiveDocument.Tables(1).Rows.Add
'label the first cell
lst.Cell(3, 1).Range.Text = "SELF"
Do While intnum < 11
Set rs = db.Execute _
("EXEC SelfEval.dbo.spSectionScore '" & par1 & "', '" & par2 & "', '" & par3 & "', '" & chgVal & "'")

'Create new column
If intnum > ActiveDocument.Tables(1).Columns.Count Then
ActiveDocument.Tables(1).Columns(ActiveDocument.Ta bles(1).Columns.Count).Select
With Selection
.Copy
.PasteSpecial
End With
End If
If Not rs.EOF Then
lst.Cell(3, intnum).Range.Text = rs("AverageScore")
Else
lst.Cell(3, intnum).Range.Text = 0
End If
intnum = intnum + 1
chgVal = chgVal + 1
Loop
rs.Close

End Sub

I can copy the values and paste them into the Chart but need a way to perform the actions dynamically. Any help on this is greatly appreciated and please assume I know very little! Thanks in advance!
__________________
SLBIBS





Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Selecting a picture in MS Word VBA zainhansrod VB How-To 1 January 2nd, 2007 03:39 AM
How to write Macro for chart for dynamically chang kotaiah Excel VBA 0 September 21st, 2006 07:28 AM
Inserting a picture from a database into Word fastcorvette Pro VB Databases 1 February 15th, 2005 07:02 PM
saving picture from word to other folder DorisTan VB How-To 0 December 3rd, 2004 02:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.