SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 266 | Next

Jim DeMarco

"Pro Excel 2007 VBA"

The InsertText subroutine finds the chart with the index
value passed in and grabs its title. It then calls the GetSubjectBody function to get the text corresponding
to the chart. Finally, it formats the text area and inserts the appropriate section
heading and text.
CHAPTER 8 n OFFICE INTEGRATION 295
4. On Standard Module1, add the code shown in Listing 8-5.
Listing 8-5. InsertText Procedure
Sub InsertText(Index As Integer)
Dim sTitle As String
Dim sBody As String
Worksheets(1).ChartObjects(Index).Activate
sTitle = ActiveChart.ChartTitle.Text
sBody = GetSubjectBody(Index)
With m_oWordApp
.Selection.Style = .ActiveDocument.Styles("Heading 2")
.Selection.TypeText sTitle
.Selection.TypeParagraph
.Selection.TypeText sBody
.Selection.TypeParagraph
End With
End Sub
The InsertChart subroutine finds the chart based upon the index value passed in, and
then applies its Copy method to place a copy of the chart on the Windows clipboard. Then we
move to the Word document and apply the Paste command at the insertion point.
5. On StandardModule1, add the code shown in Listing 8-6.
Listing 8-6. InsertChart Procedure
Sub InsertChart(Index As Integer)
Worksheets(1).ChartObjects(Index).Copy
m_oWordApp.Selection.Paste
End Sub
This completes the MakeWordDoc procedure. The finished code should look like Listing 8-7.
Listing 8-7. Complete MakeWordDoc Subroutine
Sub MakeWordDoc()
Dim i As Integer
Dim sTitle As String
Dim sBody As String
Set m_oWordApp = CreateObject("Word.


Pages:
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278