Visual Basic 6.0 and Excel

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JW

    #1

    Visual Basic 6.0 and Excel

    I am looking for sample code to learn me about using excel from a visual
    basic program.

    I want to open a file, store code in a certain cell and save this again.

    Who can help me

    Regards


  • Steve Gerrard

    #2
    Re: Visual Basic 6.0 and Excel


    "JW" <j@hetnet.nl> wrote in message news:c1a4i2$ijn $1@reader08.wxs .nl...[color=blue]
    > I am looking for sample code to learn me about using excel from a[/color]
    visual[color=blue]
    > basic program.
    >
    > I want to open a file, store code in a certain cell and save this[/color]
    again.[color=blue]
    >
    > Who can help me
    >
    > Regards
    >
    >[/color]

    This example shows the basic operations.
    Set a reference in you VB project to the Microsoft Excel Object Library.

    Private Sub Command1_Click( )
    Dim oXL As Excel.Applicati on
    Dim oWB As Excel.Workbook
    Dim oWS As Excel.Worksheet

    Set oXL = New Excel.Applicati on
    Set oWB = oXL.Workbooks.O pen("C:\Documen ts\MyFile.xls")
    Set oWS = oWB.Worksheets( "Sheet1")

    oWS.Range("B1") .Value = 23.5
    oWS.Range("B2") .Value = 17.6
    oWS.Range("B3") .Formula = "=B1+B2"

    oWB.Save

    oXL.Quit

    End Sub




    Comment

    • terry.wright

      #3
      Re: Visual Basic 6.0 and Excel

      Hi

      I have p[icked up this thread and have a student who is trying to enter data
      to Excel from a VB form and this works a treat. Is there any way to get the
      system to enter each instance into successive rows in the spreadsheet.

      e.g. first use enters to B1,C1,D1 and the next to B2,C2,D2 etc. etc.

      Regards

      Terry

      "Steve Gerrard" <notstevegerrar d@comcast.net> wrote in message
      news:IbCdnVlXc5 Whd6XdRVn-gw@comcast.com. ..[color=blue]
      >
      > "JW" <j@hetnet.nl> wrote in message news:c1a4i2$ijn $1@reader08.wxs .nl...[color=green]
      > > I am looking for sample code to learn me about using excel from a[/color]
      > visual[color=green]
      > > basic program.
      > >
      > > I want to open a file, store code in a certain cell and save this[/color]
      > again.[color=green]
      > >
      > > Who can help me
      > >
      > > Regards
      > >
      > >[/color]
      >
      > This example shows the basic operations.
      > Set a reference in you VB project to the Microsoft Excel Object Library.
      >
      > Private Sub Command1_Click( )
      > Dim oXL As Excel.Applicati on
      > Dim oWB As Excel.Workbook
      > Dim oWS As Excel.Worksheet
      >
      > Set oXL = New Excel.Applicati on
      > Set oWB = oXL.Workbooks.O pen("C:\Documen ts\MyFile.xls")
      > Set oWS = oWB.Worksheets( "Sheet1")
      >
      > oWS.Range("B1") .Value = 23.5
      > oWS.Range("B2") .Value = 17.6
      > oWS.Range("B3") .Formula = "=B1+B2"
      >
      > oWB.Save
      >
      > oXL.Quit
      >
      > End Sub
      >
      >
      >
      >[/color]


      Comment

      • Steve Gerrard

        #4
        Re: Visual Basic 6.0 and Excel

        In the previous example, you could use

        oWS.Cells(mRow, 2).Value = 23.5
        oWS.Cells(mRow, 3).Value = 17.6
        oWS.Cells(mRow, 4).Value = 19

        where mRow is a variable in the module, and the 2, 3, and 4 are column
        numbers (i.e. B, C, and D).

        So, you could start with mRow = 1, then increment it each time the
        procedure is called.

        "terry.wrig ht" <terry@wrico.ka roo.co.uk> wrote in message
        news:RtqdnTBNtc XKKcXdSa8jmw@ka roo.co.uk...[color=blue]
        > Hi
        >
        > I have p[icked up this thread and have a student who is trying to[/color]
        enter data[color=blue]
        > to Excel from a VB form and this works a treat. Is there any way to[/color]
        get the[color=blue]
        > system to enter each instance into successive rows in the spreadsheet.
        >
        > e.g. first use enters to B1,C1,D1 and the next to B2,C2,D2 etc. etc.
        >
        > Regards
        >
        > Terry
        >
        > "Steve Gerrard" <notstevegerrar d@comcast.net> wrote in message
        > news:IbCdnVlXc5 Whd6XdRVn-gw@comcast.com. ..[color=green]
        > >
        > > "JW" <j@hetnet.nl> wrote in message[/color][/color]
        news:c1a4i2$ijn $1@reader08.wxs .nl...[color=blue][color=green][color=darkred]
        > > > I am looking for sample code to learn me about using excel from a[/color]
        > > visual[color=darkred]
        > > > basic program.
        > > >
        > > > I want to open a file, store code in a certain cell and save this[/color]
        > > again.[color=darkred]
        > > >
        > > > Who can help me
        > > >
        > > > Regards
        > > >
        > > >[/color]
        > >
        > > This example shows the basic operations.
        > > Set a reference in you VB project to the Microsoft Excel Object[/color][/color]
        Library.[color=blue][color=green]
        > >
        > > Private Sub Command1_Click( )
        > > Dim oXL As Excel.Applicati on
        > > Dim oWB As Excel.Workbook
        > > Dim oWS As Excel.Worksheet
        > >
        > > Set oXL = New Excel.Applicati on
        > > Set oWB = oXL.Workbooks.O pen("C:\Documen ts\MyFile.xls")
        > > Set oWS = oWB.Worksheets( "Sheet1")
        > >
        > > oWS.Range("B1") .Value = 23.5
        > > oWS.Range("B2") .Value = 17.6
        > > oWS.Range("B3") .Formula = "=B1+B2"
        > >
        > > oWB.Save
        > >
        > > oXL.Quit
        > >
        > > End Sub
        > >
        > >
        > >
        > >[/color]
        >
        >[/color]


        Comment

        Working...