CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2011
    Posts
    1

    [RESOLVED] Adding macro from vb6 to Excel file

    Hello!
    Im trying to make a program that adds calculated variables to the new Excel file:
    Code:
    Dim appxl
     Dim Book As Excel.Workbooks
     Dim Wsheet As Excel.Worksheet
     FileName = "c:\temp\new.xls"
     Set appxl = CreateObject("Excel.Application")
     Set Book = appxl.Workbooks
     Set Wsheet = Book.Add.Worksheets(1)
     
     appxl.Visible = True
     Wsheet.Cells(1, 1) = "Zudumi H[m]"
                  ...
    End Sub
    It works fine, but I also want to build a chart using data that was inserted by my programm.
    So I recorded a macro in Excel that does that:
    Code:
    Sub Auto_open()
    ActiveSheet.Shapes.AddChart.Select
        ActiveChart.ChartType = xlXYScatterLines
        ActiveChart.SeriesCollection.NewSeries
        ActiveChart.SeriesCollection(1).Name = "='Ėčńņ1'!$C$1"
        ActiveChart.SeriesCollection(1).XValues = "='Ėčńņ1'!$A$2:$E$2"
        ActiveChart.SeriesCollection(1).Values = "='Ėčńņ1'!$A$3:$E$3"
    Now Im only looking for a way how to add this macro to the same file that is created by the first code.. I would be gateful for any help

  2. #2
    Join Date
    Dec 2008
    Location
    Step Into(F11)
    Posts
    465

    Smile Re: [RESOLVED] Adding macro from vb6 to Excel file

    Make public Sub Auto_open() .put inside the module together with all the Macro code written inside it .and just call in your projects .anywhere you want .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured