473,387 Members | 1,724 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,387 software developers and data experts.

Select data from different worksheet

39
Hi,
I'm working with VB 6 and Ms Excel. My Excel Workbook has 3 worksheets.
I want to retrieve data from one of the sheets and show it in my Flexgrid, but I don't know how to select a spesific sheet.

I've wrote this code so far:
Expand|Select|Wrap|Line Numbers
  1.     Dim xlapp As Excel.Application
  2.     Dim xlbook As Excel.Workbook
  3. Private Sub Command1_Click()
  4.     Set xlapp = New Excel.Application
  5.     Set xlbook = xlapp.Workbooks.Open("C:\XLTAB.xls")
  6.     XL
  7. End Sub
Expand|Select|Wrap|Line Numbers
  1. Private Sub XL()  
  2.     Clipboard.Clear
  3.     With xlapp.ActiveWorkbook.ActiveSheet  '------> I think I miss something here
  4.         .Range("A2:K284").Copy
  5.     End With
  6.  
  7.     With MSHFlexGrid1
  8.         .Redraw = False
  9.         .Row = 3
  10.         .Col = 2
  11.         .RowSel = MSHFlexGrid1.Rows - 1
  12.         .ColSel = MSHFlexGrid1.Cols - 1
  13.         .Clip = Replace(Clipboard.GetText, vbNewLine, vbCr)
  14.         .Col = 1
  15.         .Redraw = True
  16.     End With
  17.  
  18.     xlapp.DisplayAlerts = False
  19.     xlbook.Close
  20.     xlapp.Application.Quit
  21.     Set xlbook = Nothing
  22.     Set xlapp = Nothing
  23. End Sub
Please help.

Nairda
Jun 25 '07 #1
3 1380
Killer42
8,435 Expert 8TB
I think rather than .ActiveSheet you refer to .Sheets("nameofsheet") or .Sheets(numberofsheet).
Jun 25 '07 #2
nairda
39
I think rather than .ActiveSheet you refer to .Sheets("nameofsheet") or .Sheets(numberofsheet).

Ok, thank you.
It's working great.

Nairda
Jun 25 '07 #3
Killer42
8,435 Expert 8TB
Glad we could help. :)
Jun 25 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Ksenia Marasanova | last post by:
Hi, I have a little problem with encoding. Was hoping maybe anyone can help me to solve it. There is some amount of data in a database (PG) that must be inserted into Excel sheet and emailed....
3
by: sridevi | last post by:
Hello How to export data from ms-access database to excel worksheet using ASP. mainly i need to export data to multiple worksheets. it is very urgent to us. i have a sample code which works...
1
by: Alex | last post by:
Hi all, I've seen this noted in many posts, but nothing I've checked out gives me any clue on how to do this. Basically as my topic says, I have a DTS and I simply need to export some data...
7
by: vbnetdev | last post by:
My boss wants this done in a day. I would be happy with a week! Anyway, I have a dataset filled with data and need to populate an MS word chart with it when writing a report. Any tutorials or...
0
by: mix01 | last post by:
Hi, I am trying to get some VBA code working, but am preplex as to why it does not work. I would really appreciate any level of help. Many thanks, Mix01 Version of the program
1
by: WWUser | last post by:
I have an Excel workbook where data of a particular type is separated by "header" rows using colons to specify the data type: :DataType1 FirstDataPoint SecondDataPoint ThirdDataPoint...
0
by: hne | last post by:
Hi friends, I have an application, written in C#, in which I am updating an Excel spreadsheet with data I pull from a sql database. When I try to select a cell in where I want to begin inserting my...
2
by: mwilliams4 | last post by:
I have an Access 2003 table that I want to generate into tabbed Excel 2003 workbooks using a button on a form. The tables would need to overwrite everytime that the button would be pressed. ...
2
by: lindabaldwin | last post by:
Hello everyone, I am fairly new to VBA. I have a worksheet in Excel, named "Data Sheet" from which I am trying to query data. This worksheet contains the following data: unit (column A), date...
2
newnewbie
by: newnewbie | last post by:
I am learning VBA and need a little help with a macro that I am writing. I have a worksheet with data that I split into multiple worksheets based on criteria in one column. E.g. Column A has unique...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.