By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,968 Members | 1,589 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,968 IT Pros & Developers. It's quick & easy.

what is the difference loading excel using msflexgrid or OLE

P: 3
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.Application")
If Err <> 0 Then
Err.Clear
Set Excel = CreateObject("Excel.Application")
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.ActiveWorkbook.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.Cells(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(KeyCode 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("dir"), 3) & ""
End Sub
Sep 11 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.