473,325 Members | 2,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Using EXCEL in VB

Hi,

I want to copy data from EXCEL into FlexGrid in VB.

Can any buddy help me. It is urgent.
Jun 12 '07 #1
3 1340
Hi,

I want to copy data from EXCEL into FlexGrid in VB.

Can any buddy help me. It is urgent.

Can you tell more details about your project like what is FlexGrid and what do you want to do in it? I am doing some similar kind of project so if you can tell me what are you doing i can help you a lot...
Jun 13 '07 #2
kadghar
1,295 Expert 1GB
Hi

I hope this code helps, what it does is to put an Excel Range into a Strings Array in VB.
The code is not very good since i dont remember if there's a way to asign a range into an array without a FOR (but you can find it out in some forum... yeah right...)

Expand|Select|Wrap|Line Numbers
  1. Sub Hola()
  2. Dim i As Long
  3. Dim j As Integer
  4. Dim MaxRow As Long
  5. Dim MaxCol As Integer
  6. Dim Obj1 As Object
  7. Dim mStr1() As String
  8.  
  9. MaxRow = 10
  10. MaxCol = 10
  11.  
  12. ReDim mStr1(MaxRow, MaxCol) As String
  13. With Application.FileDialog(msoFileDialogFilePicker)
  14.     .AllowMultiSelect = True
  15.     .Filters.Clear
  16.     .Filters.Add "Excel Files (*.xls)", "*.xls"
  17.     .Show
  18.     If .SelectedItems.Count > 0 Then
  19.         Set Obj1 = CreateObject("excel.application")
  20.         Obj1.Workbooks.Open (.SelectedItems.Item(1))
  21.     End If
  22. End With
  23. For i = 1 To MaxRow
  24.     For j = 1 To MaxCol
  25.         mStr1(i, j) = Obj1.Worksheets(1).Cells(i, j)
  26.     Next
  27. Next
  28. End Sub
oh, by the way, you can add a line to see the excel worksheet and then close it or something like :

obj1.visible=true
or
obj1.activeworkbook.close savechanges:=false

Good Luck!
Jun 13 '07 #3
Thanks a lot 4 such efforts. I have done using your given help.

Hi

I hope this code helps, what it does is to put an Excel Range into a Strings Array in VB.
The code is not very good since i dont remember if there's a way to asign a range into an array without a FOR (but you can find it out in some forum... yeah right...)

Expand|Select|Wrap|Line Numbers
  1. Sub Hola()
  2. Dim i As Long
  3. Dim j As Integer
  4. Dim MaxRow As Long
  5. Dim MaxCol As Integer
  6. Dim Obj1 As Object
  7. Dim mStr1() As String
  8.  
  9. MaxRow = 10
  10. MaxCol = 10
  11.  
  12. ReDim mStr1(MaxRow, MaxCol) As String
  13. With Application.FileDialog(msoFileDialogFilePicker)
  14.     .AllowMultiSelect = True
  15.     .Filters.Clear
  16.     .Filters.Add "Excel Files (*.xls)", "*.xls"
  17.     .Show
  18.     If .SelectedItems.Count > 0 Then
  19.         Set Obj1 = CreateObject("excel.application")
  20.         Obj1.Workbooks.Open (.SelectedItems.Item(1))
  21.     End If
  22. End With
  23. For i = 1 To MaxRow
  24.     For j = 1 To MaxCol
  25.         mStr1(i, j) = Obj1.Worksheets(1).Cells(i, j)
  26.     Next
  27. Next
  28. End Sub
oh, by the way, you can add a line to see the excel worksheet and then close it or something like :

obj1.visible=true
or
obj1.activeworkbook.close savechanges:=false

Good Luck!
Jul 20 '07 #4

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

Similar topics

0
by: Jeff | last post by:
I will start off by giving you a background of the process I am taking. The nature of my DTS package is that I recieve an Excel Spreadsheet, run it through the DTS Package applying validation to...
0
by: Mike Knight | last post by:
(I've also posted this problem on microsoft.public.excel.programming) I have a MS Access 2003 Database named "AS400 Fields.mdb". This database contains links to tables on an AS400. In MS...
4
by: Chris | last post by:
Hi, everything works apart from the last line :-(( rng.Value2.ToString() An exception is thrown : "Old format or invalid type library" It gets compiled though (so he recognizes the property...
14
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the...
0
by: Rich Wallace | last post by:
Hello all, Looking for suggestions and tips if possible. I have an application running on a file server that utilizes the FileSystemWatcher to trap when any Excel files are saved by a user. I...
5
by: kewalmehra | last post by:
Hi All, I have a requirement of saving Excel files as HTML using C#. I have managed to write code for saving as HTLM file. however this seems to be not working in the once perticular case . ...
5
by: Mike in Santa Rosa | last post by:
I'm trying to get a simple c# app built that can launch/manipulate an excel workbook, sheet. I've chased down several examples and can't any of them to work. So I must be doing somethnig obviouslt...
3
by: akristensen | last post by:
I am new to this site, so be patient if I do not ask the question correctly. Current Target Platform: Browser: MS IE, script language: Javascript (will use VBScript, but JS is preferred), External...
0
by: wankhusairi | last post by:
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...
7
by: =?Utf-8?B?VGVycnkgSG9sbGFuZA==?= | last post by:
I have a vb.net app that opens an excel worksheet, reads data and then closes the sheet. Im noticing that the Excel process is still running after I have closed and disposed of my excel objects. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.