Как сделать диаграмму в Word из VB
Формулировка задачи:
Необходимо вывести данные в виде диаграммы из VB в Word.
Спасибо всем, кто поможет
Решение задачи: «Как сделать диаграмму в Word из VB»
textual
Листинг программы
- Private Sub Command1_Click()
- Dim sFileName As String
- sFileName = App.Path & '
- wind.mdb'
- ' Declare our variables
- Dim oWord As Word.Application
- Dim oDoc As Word.Document
- Dim oRange As Word.Range
- Dim oConn As ADODB.Connection
- Dim oRS As ADODB.Recordset
- Dim sTemp As String
- ' Create an instance of Word
- Set oWord = CreateObject('Word.Application')
- ' Show Word to the user
- oWord.Visible = True
- ' Add a new, blank document
- Set oDoc = oWord.Documents.Add
- ' Get the current document's range object
- Set oRange = oDoc.Range
- ' Create a new ADO connection
- Set oConn = CreateObject('ADODB.Connection')
- ' Open our connect
- On Error Resume Next
- oConn.Open 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' & _
- sFileName & ';Persist Security Info=False'
- ' Execute a SQL statement to retrieve the information
- Set oRS = oConn.Execute( _
- 'SELECT CustomerID, CompanyName, ContactName FROM Customers')
- ' Use GetString to return the recordset as a string
- sTemp = oRS.GetString(adClipString, -1, vbTab)
- ' Insert a heading on the string
- sTemp = 'Customer ID' & vbTab & 'Company Name' & _
- vbTab & 'Contact Name' & vbCrLf & sTemp
- On Error GoTo 0
- ' Insert the data into the Word document
- oRange.Text = sTemp
- ' Convert the text to a table and format the table
- oRange.ConvertToTable vbTab, , , , wdTableFormatColorful2
- 'Insert documentChart
- oWord.Selection.InlineShapes.AddOLEObject ClassType:='MSGraph.Chart.8', _
- LinkToFile:=False, DisplayAsIcon:=False
- End Sub
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д