Problem with Excel file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dyc
    New Member
    • May 2007
    • 32

    Problem with Excel file

    Can anyone give a simple example, showing how to read data from excel or in other word which means that extract the necessary data from Excel file....
    Can someone show me the step?Firstly what should I do..What thing should I declare and so on...

    Thanks.
  • collin
    New Member
    • Jul 2007
    • 3

    #2
    Originally posted by dyc
    Can anyone give a simple example, showing how to read data from excel or in other word which means that extract the necessary data from Excel file....
    Can someone show me the step?Firstly what should I do..What thing should I declare and so on...

    Thanks.

    Put this into your module
    Public xLAppSrc As Object
    Public xlwksheet As excel.Applicati on


    Put this into your current form
    Dim TxtA_One, TxtB_One as String

    Set xLAppSrc = CreateObject("E xcel.applicatio n")
    'OPen Excel File with full path and file name
    xLAppSrc.workbo oks.Open FileName:=cPath + SrcFileName

    xLAppSrc.worksh eets.Select
    xLAppSrc.range( (Trim("A1"))).S elect
    TxtA_One = xLAppSrc.active cell
    xLAppSrc.range( (Trim("B1"))).S elect
    TxtB_One= xLAppSrc.active cell

    txtDisplay = TxtA_One & " " & TxtB_One

    ' Must use two line to Quit otherwise the application remains open
    xLApp1.Quit
    Set xLApp1 = Nothing

    I hope this helps you as I am not an expert in VB.

    Cheers Collin Pillay

    Comment

    • dyc
      New Member
      • May 2007
      • 32

      #3
      Originally posted by collin
      Put this into your module
      Public xLAppSrc As Object
      Public xlwksheet As excel.Applicati on


      Put this into your current form
      Dim TxtA_One, TxtB_One as String

      Set xLAppSrc = CreateObject("E xcel.applicatio n")
      'OPen Excel File with full path and file name
      xLAppSrc.workbo oks.Open FileName:=cPath + SrcFileName

      xLAppSrc.worksh eets.Select
      xLAppSrc.range( (Trim("A1"))).S elect
      TxtA_One = xLAppSrc.active cell
      xLAppSrc.range( (Trim("B1"))).S elect
      TxtB_One= xLAppSrc.active cell

      txtDisplay = TxtA_One & " " & TxtB_One

      ' Must use two line to Quit otherwise the application remains open
      xLApp1.Quit
      Set xLApp1 = Nothing

      I hope this helps you as I am not an expert in VB.

      Cheers Collin Pillay
      Thanks for ur value reply..I copy the code and put it in the consoleApplicat ion's window..do I need import anything??And I'm using VB2005 instead of VB6,it's not supported excel.Applicati on....an error occur...what happen?

      Thanks!

      Comment

      Working...