what is the difference loading excel using msflexgrid or OLE

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wankhusairi
    New Member
    • Sep 2007
    • 3

    what is the difference loading excel using msflexgrid or OLE

    hallo sir .. i am still new on using vb and i have tried to load an excel using a visual basic interface.. but if i wanted to plot my excel data what should i do.. must i cahnge my program on loading the excel by using OLE or Msflexgrid.. i am very confuse..hope u can give me some tip on how should i plot my graph using the visual basci interface. here i gave my program:

    Option Explicit
    Dim Excel As Object
    Dim ExcelSheet As Object
    Dim Workbooks As Object
    Private Sub CmdLoad_Click()
    Dim i As Long
    Dim n As Long
    Set Excel = Nothing
    Set ExcelSheet = Nothing
    Set Workbooks = Nothing
    Dim filename As String
    filename = Dir1.Path & "\" & File1.filename
    On Error Resume Next
    Set Excel = GetObject(, "Excel.Applicat ion")
    If Err <> 0 Then
    Err.Clear
    Set Excel = CreateObject("E xcel.Applicatio n")
    If Err <> 0 Then
    MsgBox "Could Not load Excel.", vbExclamation
    End
    End If
    End If
    Excel.Visible = True ' show the excel screen
    Excel.Workbooks .Open filename ' open the selected or mentioned file
    Set ExcelSheet = Excel.ActiveWor kbook.Sheets(1) ' open the first sheet in the workbook

    With MSFlexGrid1
    .Cols = 10
    .Rows = 110
    For i = 0 To .Rows - 1
    .Row = i
    For n = 0 To .Cols - 1
    .Col = n
    .Text = ExcelSheet.Cell s(i + 1, n + 1).Value
    Next
    Next
    End With
    End Sub


    Private Sub CmdClose_Click( )
    Unload Me
    End Sub

    Private Sub File1_Click()
    Label2.Caption = Dir1.Path & "\" & File1.filename ' display the current path and file name in the label2.caption which is present at the bottom of the form
    End Sub

    Private Sub File1_DblClick( )
    Call CmdLoad_Click 'if the user double clicks the mouse by selecting the file
    End Sub

    Private Sub File1_KeyPress( KeyAscii As Integer)
    If KeyAscii = 13 Then Call Command1_Click ' if the user presses enter key by selecting the file
    End Sub

    Private Sub Form_KeyDown(Ke yCode As Integer, Shift As Integer)
    If KeyCode = 27 Then Unload Me
    End Sub


    Private Sub Dir1_Change()
    Label2.Caption = Dir1.Path ' display the current directory path
    File1.Path = Dir1.Path ' change the file path with relevant to the directory path
    End Sub

    Private Sub Drive1_Change()
    Dir1.Path = Drive1.Drive ' change the directory path relevant to the drive path
    End Sub

    Private Sub Form_Load()
    File1.Pattern = "*.xls" ' set the filelist box to open only the files which has extension .xls
    Dir1.Path = Left(Environ("d ir"), 3) & ""
    End Sub
Working...