Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

to import data from excel sheet

 
   Database Help (Home) -> Visual Basic RSS
Next:  Access/VB Date Format Problem  
Author Message
Kirat

External


Since: Jun 07, 2004
Posts: 2



(Msg. 1) Posted: Mon Jun 07, 2004 4:54 pm
Post subject: to import data from excel sheet
Archived from groups: comp>lang>basic>visual>database (more info?)

Hi all,

I am begineer for visual basics but have enough experience of the
programming.
This is first time i am working something with database. What i need
to do is in visual basic pro. import data from excel file and store it
into the array.
excel file is only 1 column 1 row file.

Plese give me suggestion
how can i do this.

-Thanks
kirat

 >> Stay informed about: to import data from excel sheet 
Back to top
Login to vote
Max Kudrenko

External


Since: Jun 09, 2004
Posts: 3



(Msg. 2) Posted: Wed Jun 09, 2004 12:17 pm
Post subject: Re: to import data from excel sheet [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Kirat,

You can do something like this:

Dim xWd As Object
Dim arr() As String

Sub doIt()
Dim iLimit As Long, iColumn As Long
iLimit = 6
iColumn = 4
Set xEx = CreateObject("Excel.Application")
Set xBx = xEx.Workbooks
xBx.Open "E:\Doc\Test1.xls"
ReDim arr(1 To iLimit)
For i = 1 To 6
arr(i) = xBx(1).ActiveSheet.Cells(i, iColumn)
Debug.Print arr(i)
Next
xEx.Quit
Set xBx = Nothing
Set xEx = Nothing

End Sub

Private Sub Command1_Click()
Call doIt
End Sub

Hope this helps,

Max Kudrenko
Brainbench MVP Program for Visual Basic
<a rel="nofollow" style='text-decoration: none;' href="http://www.brainbench.com" target="_blank">www.brainbench.com</a>


kirat.shah.TakeThisOut@allvac.com (Kirat) wrote in message ...
 > Hi all,
 > I am begineer for visual basics but have enough experience of the
 > programming.
 > This is first time i am working something with database. What i need
 > to do is in visual basic pro. import data from excel file and store it
 > into the array.
 > excel file is only 1 column 1 row file.
 > Plese give me suggestion
 > how can i do this.
 > -Thanks
 > kirat

 >> Stay informed about: to import data from excel sheet 
Back to top
Login to vote
Kirat

External


Since: Jun 07, 2004
Posts: 2



(Msg. 3) Posted: Thu Jun 10, 2004 11:13 am
Post subject: Re: to import data from excel sheet [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thanks for helping me on this issue

I tried that and i was successful to read data but problem is
excel.exe is continously running in the program and untill i end that
program, i can not able to open that worksheet.

plese let me know if i missed something.
-thanks
kirat

This is my program that i made

Option Explicit

Private xlsApp As Excel.Application
Private xlsWB As Excel.Workbook
Private Sub Command1_Click()
Set xlsApp = CreateObject("Excel.Application")
Static xlfilename As String
xlfilename = Text1.Text
Set xlsWB = xlsApp.Workbooks.Open(xlfilename)
Static Lines As Integer
Static intmsg As String
Static CellData As Integer
Static maxline, mvalue As Integer
' fill the spreadsheet control with the contents of the actual
file
' this keeps the actual file intact
' Open import file,,readonly


' ' get how many records are in the excel file for the progress bar
Static xlWorksheet As String
xlWorksheet = "sheet1"
Static ncycle As Integer
ncycle = Val(Text2.Text)
Dim StrVar(1000, 1000) As Integer
' Lines = 1
'CellData = 2 ' need to have something to start the loop
'Do While CellData <> 10101
' CellData = xlsApp.ActiveCell.Cells(Lines, 1)
' Lines = Lines + 1
'Loop

' loop through the data and save it to the preview table
'maxline = Lines - 1
Static CellRow, CellCol, BlankCell As Integer
CellRow = 0
Do While CellRow <= ncycle
CellRow = CellRow + 1
If xlsWB.Worksheets(xlWorksheet).Cells(CellRow, 1) = 10101 Then
Exit Do
CellCol = 1
BlankCell = 0
Do While CellCol <= 2
StrVar(CellRow, CellCol) =
xlsWB.Worksheets(xlWorksheet).Cells(CellRow, CellCol)

CellCol = CellCol + 1
Loop
mvalue = CellRow
Loop

xlsWB.Close

' Quit Excel.
xlsApp.Quit

' Close the object references.
Set xlsWB = Nothing
Set xlsApp = Nothing
mvalue = 0
intmsg = MsgBox("done")
End Sub
 >> Stay informed about: to import data from excel sheet 
Back to top
Login to vote
Max Kudrenko

External


Since: Jun 09, 2004
Posts: 3



(Msg. 4) Posted: Fri Jun 11, 2004 7:12 am
Post subject: Re: to import data from excel sheet [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Kirat,

Your code does look strange (especially the use of Static variables)
but opening and closing the Excel application is fine. It should work
properly even if you already have Excel running. It will open and
close a new instance automatically. It's tested for Excel 97, however.
If you have another version, the behaviour might be different.

Hope this helps,

Max Kudrenko
Brainbench MVP Program for Visual Basic
<a rel="nofollow" style='text-decoration: none;' href="http://www.brainbench.com" target="_blank">www.brainbench.com</a>


kirat.shah.DeleteThis@allvac.com (Kirat) wrote in message ...
 > Thanks for helping me on this issue
 > I tried that and i was successful to read data but problem is
 > excel.exe is continously running in the program and untill i end that
 > program, i can not able to open that worksheet.
 > plese let me know if i missed something.
 > -thanks
 > kirat
 > This is my program that i made
 >
 > Option Explicit
 > Private xlsApp As Excel.Application
 > Private xlsWB As Excel.Workbook
 > Private Sub Command1_Click()
 > Set xlsApp = CreateObject("Excel.Application")
 > Static xlfilename As String
 > xlfilename = Text1.Text
 > Set xlsWB = xlsApp.Workbooks.Open(xlfilename)
 > Static Lines As Integer
 > Static intmsg As String
 > Static CellData As Integer
 > Static maxline, mvalue As Integer
 > ' fill the spreadsheet control with the contents of the actual
 > file
 > ' this keeps the actual file intact
 > ' Open import file,,readonly
 >
 >
 > ' ' get how many records are in the excel file for the progress bar
 > Static xlWorksheet As String
 > xlWorksheet = "sheet1"
 > Static ncycle As Integer
 > ncycle = Val(Text2.Text)
 > Dim StrVar(1000, 1000) As Integer
 > ' Lines = 1
 > 'CellData = 2 ' need to have something to start the loop
 > 'Do While CellData <> 10101
 > ' CellData = xlsApp.ActiveCell.Cells(Lines, 1)
 > ' Lines = Lines + 1
 > 'Loop
 > ' loop through the data and save it to the preview table
 > 'maxline = Lines - 1
 > Static CellRow, CellCol, BlankCell As Integer
 > CellRow = 0
 > Do While CellRow <= ncycle
 > CellRow = CellRow + 1
 > If xlsWB.Worksheets(xlWorksheet).Cells(CellRow, 1) = 10101 Then
 > Exit Do
 > CellCol = 1
 > BlankCell = 0
 > Do While CellCol <= 2
 > StrVar(CellRow, CellCol) =
 > xlsWB.Worksheets(xlWorksheet).Cells(CellRow, CellCol)
 > CellCol = CellCol + 1
 > Loop
 > mvalue = CellRow
 > Loop
 > xlsWB.Close
 > ' Quit Excel.
 > xlsApp.Quit
 > ' Close the object references.
 > Set xlsWB = Nothing
 > Set xlsApp = Nothing
 > mvalue = 0
 > intmsg = MsgBox("done")
 > End Sub
 >> Stay informed about: to import data from excel sheet 
Back to top
Login to vote
Steve Gerrard

External


Since: Sep 05, 2003
Posts: 56



(Msg. 5) Posted: Fri Jun 11, 2004 9:02 pm
Post subject: Re: to import data from excel sheet [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Kirat" wrote in message

 > xlsWB.Close
 >
 > ' Quit Excel.
 > xlsApp.Quit
 >
 > ' Close the object references.
 > Set xlsWB = Nothing
 > Set xlsApp = Nothing

You might try changing the order here. Excel will not unload if a
workbook object is still alive. Something like:
xlsWB.Close
Set xlsWB = Nothing
xlsApp.Quit
Set xlsApp = Nothing
 >> Stay informed about: to import data from excel sheet 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Retrieving data from a MSHFlexGrid - I've managed to set up an MSHFlexGrid and store it with data from an Access DB successfully. What I'm trying to do is retrieve data from a selected row but I'm not sure what methods I need to call to get this data. Can anyone tell me how to do this o...

New record with data from other form - I would like to open a addrecord form. In this form I would like teh Field DebNr to be filled with the value of the field DebNr in my (open) form FrmStam. I used the VisualBasic code ; Private Sub Form_Open(Cancel As Integer) If IsOpen("Frm...

data environment in data report- error?Why - I have a vb project and I have used data reports. The reports are working perfectly well here. But when I copy the whole folder to another machine, I cannot open the DataEnvironment and it shows error. Why?All the forms and reports can be opened in..

NEWBIE insert data rather than update in db - I have an app for tracking mileage on company vehicles. On the first form you select a vehicle(via combobox getting vehicle names from database) and enter the appropriate info. Then I need to export that data back to the database. The ? is how do I....

Data Environment Designer - need additional table fields o.. - Hello -- There are too many columns in the table to fit on a form when dragging the DED's table's Command node onto the form. I need to add to the form some of those columns which did not come onto the form in that initial dragging. After dragging..
   Database Help (Home) -> Visual Basic All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]