Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel 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 August 24th, 2007, 11:42 AM
Registered User
 
Join Date: Aug 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Generation of graphs in excel vba

Hello all,
I have generated data in an excel VBA module and would like to generate a simple graph still in vba then export it to Microsoft Word. Is that at all possible or am I dreaming in technicolour.
Cheers

Paul
 
Old August 31st, 2007, 07:47 AM
Registered User
 
Join Date: Aug 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Generate data in range A1:B10 of Sheet1 and run following code:
Code:
Sub ChartInWord()

    Dim BWord As Object
    Dim BDoc As Object

    'create chart
    Charts.Add
    With Charts(1)
        .ChartType = xlColumnClustered
        .SetSourceData Source:=Sheets("Sheet1").Range("A1:B10"), PlotBy:= _
            xlColumns
        .Location Where:=xlLocationAsObject, Name:="Sheet1"
    End With
    ActiveChart.ChartArea.Copy

    'create document Word
    Set BWord = CreateObject("Word.Application")
    With BWord
        .Visible = True ' may not show
        .documents.Add
        Set BDoc = .documents(1)
        .Selection.Paste
        BDoc.SaveAs Filename:="c:\MyWord.doc"
        .Quit
    End With

    Set BWord = Nothing
    Set BDoc = Nothing

End Sub
 
Old August 31st, 2007, 10:29 AM
Registered User
 
Join Date: Aug 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a million Bi-lya, you are a champ.
It works perfectly.
paul

Paul





Similar Threads
Thread Thread Starter Forum Replies Last Post
Code works in Excel VBA but not Access VBA fossx Access VBA 2 May 21st, 2007 08:00 AM
Export Data to Excel & Generate Graphs vinod_pawar1 ASP.NET 1.0 and 1.1 Professional 3 July 15th, 2006 01:03 AM
Converting excel data to Access using excel VBA ShaileshShinde VB Databases Basics 1 April 26th, 2006 07:57 AM
Copying Excel Graphs into PPT presentation malocher Beginning VB 6 0 March 28th, 2005 11:21 AM
Excel VBA to SQL & back to VBA edesousa Excel VBA 1 June 1st, 2004 02:39 AM





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