473,473 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to refer a particular excel sheet through vb6 code

21 New Member
I am doing a small project using vb6 and automating Excel through vb6

First, I will tell about my project briefly
I am trying to save the database of 3 kinds of books
I used VB6 forms as the user interface
I coded VB6 in the way to accept the user's entry and saving it in Excel sheet

I created 12 worksheets in an Excel workbook and re-named it from Jan, Feb,....till Dec

I used
Set oXLSheet=oXLBook.Worksheets(1) to refer the first worksheet
Ya.it is successful
When the user enters data, it automatically save the data in first worksheet

But when i change it to
Set oXLSheet=oXLBook.Worksheets(2), the data is not stored in the second sheet. i hope my code is correct. But the code which follows it showing the error "Activate method of Range class failed"

I will paste my code below
Expand|Select|Wrap|Line Numbers
  1. // I set the Excel object variables here//
  2.  
  3. Set oXLBook = oXLApp.Workbooks.Open(TheFileName)
  4. Set oXLSheet = oXLBook.Worksheets(1)
  5. Set oXLRange = oXLSheet.UsedRange
  6.  
  7. // I gave the value of E1 and F1 cells as "BOOKS Records here "//
  8.  
  9. oXLSheet.Range("E1:F1").Value = "BOOKS RECORDS"
  10.  
  11. // I left two rows blank after the activated cell "F1" here //
  12.  
  13. oXLRange.SpecialCells(xlCellTypeLastCell).Activate
  14.  
  15. BlankRowNum = oXLApp.ActiveCell.Row + 1
  16.  
  17. NextToBlankRow = oXLSheet.Cells(BlankRowNum, 1).Offset(1, 0).Row + 1
  18.  
  19. // I gave a cell value as "record" after the 2 blank rows //
  20.  
  21. TitleRowCell = "E" & NextToBlankRow
  22. oXLSheet.Range(TitleRowCell) = "RECORD"
  23.  
  24. // I activated the cell with value "record" and saved the BooksNames values following the activated cell //
  25.  
  26. oXLRange.SpecialCells(xlCellTypeLastCell).Activate
  27.  
  28. newFstRow = oXLApp.ActiveCell.Row + 1
  29.  
  30. newFstCell = "E" & newFstRow
  31. oXLSheet.Range(newFstCell) = BooksNamesTitle
  32. newScndCell = "F" & newFstRow
  33. oXLSheet.Range(newScndCell) = BooksNamesWithNum
Everthing is working

But when i referred the sheet number other than 1 such as
Set oXLSheet=oXLBook.Worksheets(2), it is not working and it gives the error "Activate method of range class failed"

I understand none of the cells are activated. But i am not sure how to solve it

Please help me out with this
Thank you
May 5 '12 #1
3 1786
Luuk
1,047 Recognized Expert Top Contributor
sorry, i dont have Exel on my computer.....
May 5 '12 #2
Hema Suresh
21 New Member
Its ok
thank u.................................
May 6 '12 #3
NeoPa
32,556 Recognized Expert Moderator MVP
Like cells, worksheets can also be selected and activated (not the same). I suspect the reference is determined to be invalid either because the specified worksheet itslef is not a selected sheet, or because no references to non-selected sheets can take place while the workbook is still in a hidden state. Try playing with those ideas and see what you find.
May 24 '12 #4

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

Similar topics

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...
9
by: dba123 | last post by:
I need some help and direction on what classes and an example or two (article) on how to read an Excel Worksheet and insert one column into a database table column. I am using .NET 2.0 only. What...
2
by: krissh | last post by:
I know How Excel sheet in php .But wat i want is how to create Multiple sheets in Excel . This is the code for creating one excel sheet <?php header('Content-type:application/ms-xls'); ...
1
by: gowthamkumar | last post by:
HII ... please give me a code to open a new excel sheet using VB so that i can also directly add some contents in the cells of the excel sheet in VB itself .. i ve use the existing excel sheet code...
1
by: runway27 | last post by:
1. I need to export data that is in a table to an excel sheet with the field names on top followed by the values of the fields. I know how to extract the data and display with echo statement,...
6
by: poolboi | last post by:
hi all, i've got the following program that needs yr help: use Win32::OLE; # use existing instance if Excel is already running eval {$ex =...
7
by: TG | last post by:
hi! I am trying to create a sql server table from an excel sheet. Here is the code I have: 'This procedure the xlsx file and dumps it to a table in SQL Server
1
by: PeacefulSoul | last post by:
Hello, I have a lot of excel sheets which columns are slightly different, i want to import all of these sheets (one at a time) into ONE SQL TABLE. I'll give an example : Say ive written the...
2
by: Pradeep23 | last post by:
Hi all, I want to export 1 big excel workbook containing 200 Sheets in it, and is classified according to Class. Each sheet name is unique according to the class. I am building a package to...
0
by: nam pai | last post by:
im using java excel api and trying to add some more records to the existing excel sheet. im using writable workbook hence every time i try to add a record it creates a new workbook and writes the...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.