•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 391,170 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,468 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser:
Views: 145294 | Replies: 23 | Solved
![]() |
| |
•
•
Join Date: Jul 2004
Location: Adelaide, Australia
Posts: 191
Reputation:
Rep Power: 5
Solved Threads: 1
•
•
•
•
Originally Posted by dtbn
Hi,
I already have an excel file (MyXL.xls) and a Visual Basic (Form1.frm) with a command button. Now, I want to write a code for the Visual Basic so that when I click on the command button, the excel file will be opened.
Any help is significant to me! Thank you in advance.
DTBN
Include excel type library in the project references and then use the following:
Dim xlTmp As Excel.Application Set xlTmp = New Excel.Application xlTmp.Workbooks.Open "MyXL.xls"
Cheers,
Mark Nemtsas
Time and Billing Software - Time Tracking Software - Roller Shutters - Roller Blinds -
Baby Books
Time and Billing Software - Time Tracking Software - Roller Shutters - Roller Blinds -
Baby Books
•
•
Join Date: Dec 2004
Location: Lincoln Park, Michigan
Posts: 1,744
Reputation:
Rep Power: 7
Solved Threads: 107
•
•
Join Date: Dec 2004
Location: Lincoln Park, Michigan
Posts: 1,744
Reputation:
Rep Power: 7
Solved Threads: 107
•
•
Join Date: Mar 2006
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 1
•
•
•
•
Originally Posted by manal
No......it dose have value
i want to write program that read the names of student of specific section from excel file and display it in textbox
actually each cell has name of student
Not sure if you've solved this yet. I had exactly the same problem. Got this to work eventually. I needed to explicitly declare a1 as a range
Dim xlApp As Excel.Application = New Excel.Application
xlApp.DisplayAlerts = False
xlApp.Workbooks.Open("c:\test.xls")
Dim xlSht As Excel.Worksheet = xlApp.Sheets(1)
Dim xlRng As Excel.Range = xlSht.Cells(1, 1)
Textbox1.Text = xlRng.Value
Dan
•
•
Join Date: Mar 2006
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 1
•
•
•
•
Originally Posted by seagull
Not sure if you've solved this yet. I had exactly the same problem. Got this to work eventually. I needed to explicitly declare a1 as a range
Dim xlApp As Excel.Application = New Excel.Application
xlApp.DisplayAlerts = False
xlApp.Workbooks.Open("c:\test.xls")
Dim xlSht As Excel.Worksheet = xlApp.Sheets(1)
Dim xlRng As Excel.Range = xlSht.Cells(1, 1)
Textbox1.Text = xlRng.Value
Dan
I used your code to open an Excel file and store its cells in an array
but it gives me run_time error7 : out of memory
and when I check the task manager Excel.EXE is still running and the computer become slow.
Private Sub Form_Load()
Dim xlTmp As Excel.Application
Set xlTmp = New Excel.Application
xlTmp.Workbooks.Open "C:\Book1.xls"
Dim xlSht As Excel.Worksheet
Set xlSht = xlTmp.Sheets(1)
ReDim Preserve Ucode2(50, 5)
For i = 2 To xlSht.Cells.Rows
Ucode2(i, 0) = xlSht.Cells(i, 1)
Ucode2(i, 1) = xlSht.Cells(i, 2)
Next
xlTmp.Workbooks.Close
xlTmp.Quitand I wanted to display this array in two different boxes :
Function show1()
For i = 0 To UBound(Ucode2)
textb0x3 = TextBox3 + Ucode2(i, 0)
TextBox2 = TextBox2 + Ucode2(i, 1)
Next
End Functionand I called this function by this button click
Private Sub CommandButton1_Click() Call show1 End Sub
•
•
Join Date: Mar 2006
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 1
Sorry,
I did a bad thing. I just put part of the code. You should release all the COM objects when done with them in reverse order. That's every workbook, sheet, range etc. something like:
Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
Dim xlApp As Excel.Application
Dim xlSht As Excel.Worksheet
Dim xlRng As Excel.Range
Try
xlApp = New Excel.Application
xlApp.DisplayAlerts = False
xlApp.Workbooks.Open("c:\test.xls")
xlSht = xlApp.Sheets(1)
xlRng = xlSht.Cells(1, 1)
Textbox1.Text = xlRng.Value
Catch ex As Exception
Textbox1.Text &= ex.ToString
Finally
xlApp.Workbooks.Close()
ReleaseComObject(xlRng)
ReleaseComObject(xlSht)
ReleaseComObject(xlApp)
xlSht = Nothing
xlApp = Nothing
GC.Collect()
End Try
End Sub
Dan
I did a bad thing. I just put part of the code. You should release all the COM objects when done with them in reverse order. That's every workbook, sheet, range etc. something like:
Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
Dim xlApp As Excel.Application
Dim xlSht As Excel.Worksheet
Dim xlRng As Excel.Range
Try
xlApp = New Excel.Application
xlApp.DisplayAlerts = False
xlApp.Workbooks.Open("c:\test.xls")
xlSht = xlApp.Sheets(1)
xlRng = xlSht.Cells(1, 1)
Textbox1.Text = xlRng.Value
Catch ex As Exception
Textbox1.Text &= ex.ToString
Finally
xlApp.Workbooks.Close()
ReleaseComObject(xlRng)
ReleaseComObject(xlSht)
ReleaseComObject(xlApp)
xlSht = Nothing
xlApp = Nothing
GC.Collect()
End Try
End Sub
Dan
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 3 (0 members and 3 guests)
•
•
•
•
•
•
•
•
DaniWeb Visual Basic 4 / 5 / 6 Marketplace
•
•
•
•
3d apple blue screen cocoa computer crash dell development drivers email enterprise eudora firefox framework games gnu graphics ibm intel internet java linux microsoft microsystems mozilla news next open open source open-source opengl openoffice operating os penelope programming red hat rhel server software source step sun super system ubuntu vista wesnoth windows xp
- Open Excel File (VB.NET)
- "Cannot Open Include File" MS Visual C++ error (C++)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: SPI data transfer to Atmega8 by VB6 through parallel port
- Next Thread: Visual Basic Timer/Clock/Countdown.



Hybrid Mode