Hi,
i cant read in data from excel 97 using vb.net 2003.
I get an exception error .
all i want to do is read in values from excel initially. I want to just test it using msgbox. -
Dim XL As Object 'workaround for excel 97
-
XL = Interaction.CreateObject("Excel.Application")
-
Dim XlWbk As Excel.Workbook = XL.Workbooks.Add()
-
-
Dim MyString As String
-
MyString = Now().ToString("yyyy-MM-dd")
-
Try
-
-
' XL.Visible = True
-
-
-
Dim XlSh As Excel.Worksheet = CType(XlWbk.Sheets(1), Excel.Worksheet)
-
Dim range As Excel.Range
-
Dim xlWsheet As Excel.Worksheet = XL.Worksheets("Sheet1")
-
Dim r As Excel.Range
-
-
XlWbk = XL.Workbooks.Open("mytest.xls")
-
-
XlWbk.Activate() '' System.Runtime.InteropServices.COMException,
-
range = XlSh.Range("A1").Value
-
-
XlWbk.Close()
-
-
-
XL.Quit()
-
MsgBox(r.Cells(0, 1).Value)
-
-
6 2904 QVeen72 1,445
Recognized Expert Top Contributor
Hi,
In VB.net, "Activate" is used for many Objects. May be the error is because of that, use "CType" -
Dim XL As Object 'workaround for excel 97
-
XL = Interaction.CreateObject("Excel.Application")
-
Dim XlWbk As Excel.Workbook = XL.Workbooks.Add()
-
-
Dim MyString As String
-
MyString = Now().ToString("yyyy-MM-dd")
-
Try
-
-
' XL.Visible = True
-
-
-
Dim XlSh As Excel.Worksheet = CType(XlWbk.Sheets(1), Excel.Worksheet)
-
Dim range As Excel.Range
-
Dim xlWsheet As Excel.Worksheet = XL.Worksheets("Sheet1")
-
Dim r As Excel.Range
-
-
XlWbk = XL.Workbooks.Open("mytest.xls")
-
-
XlWbk= CType(XL.Workbooks.Item(1), Excel.WorkBook)
-
-
XlWbk.Activate()
-
range = XlSh.Range("A1").Value
-
-
XlWbk.Close()
-
-
-
XL.Quit()
-
MsgBox(r.Cells(0, 1).Value)
-
-
REgards
Veena
Hi,
I have changed the code and still get an error when i simply try to display a value from excel.
Dim XL As Object
XL = Interaction.Cre ateObject("Exce l.Application")
Dim XlWbk As Excel.Workbook = XL.Workbooks.Ad d()
Try
' XlSh.Range("A2" ).Value = MyString 'Set a value
Dim xlsApp As Excel.Applicati on
Dim xlsWB As Excel.Workbook
Dim xlsSheet As Excel.Worksheet
Dim xlsCell As Excel.Range
Dim xlsDatei As String
xlsApp = New Excel.Applicati on
' xlsApp.Visible = True
xlsWB = xlsApp.Workbook s.Open("book1.x ls")
xlsSheet = xlsWB.Worksheet s(1)
'xlsCell = xlsSheet.Range( "A1") xlsCell = xlsSheet.Cells( 1, 1).value() 'cast error
MsgBox(xlsCell)
also i cant use ctype with activate
CType(XlWbk, Excel.Worksheet ).Activate() 'error
I cant find any basic tutorial with vb.net and excel where you can read data from a excel file and write values back eg just summing up a few columns and write back the total.
Is this all possible because i have spent hours on seemingly just basici connection and basic tasks. Where is the help in vb.net for excel?
QVeen72 1,445
Recognized Expert Top Contributor
Hi,
I have changed the code in 19th line.(prev post)
You have not done the changes in your code..
WorkBook cannot be Casted to Worksheet.. Try This:
CType(XlWbk, Excel.WorkBook) .Activate()
Regards
Veena
i still get an error as before with this -
-
-
Dim XlSh As Excel.Worksheet = CType(XlWbk.Sheets(1), Excel.Worksheet)
-
Dim range As Excel.Range
-
-
XlWbk = XL.Workbooks.Open("mytest.xls")
-
XlWbk = CType(XL.Workbooks.Item(1), Excel.Workbook)
-
CType(XlWbk, Excel.Workbook).Activate() 'same error as before
-
-
-
i can connect now to a excel sheet and open and save to it.
Is there a way to assign a range of values read in from excel moved to a datagrid?
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Dianna K |
last post by:
I am opening, reading and extracting an Excel spreadsheet in .Net (VB). It seems to work fine, however, when I am finished and I open up Excel and try to open up the file a message pops up "File Now Available", "select Read-Write or Cancel". Its almost like my code is changing the documents attributes. Am I doing something wrong in my code
Any help would be great. Thanks
Diann
PS: I'm not quite sure why, but it seems that I have to use...
|
by: Peter |
last post by:
I am having a problem reading an Excel file that is XML based. The directory
I am reading contains Excel files that can be of two types. Either generic Microsoft
based or XML based. I am reading the Microsoft based files with an OleDbDataAdapter.
Then filling the contents of the first worksheet into a dataset.
However when I try to add the XML based file to my dataset using an XmlTextReader
I can never seem to get it to save to a...
|
by: Marco Aschwanden |
last post by:
Hi
I would like to
1. import an existing Excel-sheet (a template)
2. and add some data to it
3. and save it under a different name afterwards.
To me it seems, that pyExcelerator does not support the reading for
modification of an Excel-sheet. It allows only the "parse_xls" but I would
like to keep the "formatting" in the template.
|
by: vinidimple |
last post by:
Hi
i have a serious problem while i was working in Excel.I want to fetch
columns from an excel worksheet and i need to compare it with an sql
querry fields,so i tried to open an excle worksheet first..
Unfortunately my code was throwing error like
|
by: sorcerdon |
last post by:
Hello experts,
I am currently opening an excel file from a VB.net application.
The excel spreadsheet gets all its data from a Dataset.
I need to hide a column form the results.
I dont want the users to have access to that perticular column in the
excel spreadsheet.
Here is my current code:
| |
by: aotemp |
last post by:
Hi,
Im having a reaaally hard time with something... Im trying to read a
cell of data into a String variable. It seems like such a simple task
too... Get the excel spreadsheet, get the workbook, get the sheet, get
the cell, get the cells data and store it into a string.
But it wont work! Im really frustrated. the best I got was
"System.___ComObject" coming out of the string.
|
by: barbara_dave |
last post by:
Hi All,
I need to read data from a Excel spreadsheet, but I got the problem
when I tried the code below:
StringBuilder sbConn = new StringBuilder();
sbConn.Append(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" );
sbConn.Append(excelFile);
sbConn.Append(";Extended Properties=");
sbConn.Append(Convert.ToChar(34));
|
by: sejal17 |
last post by:
hello
Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store that multiple worksheet data in different table.How can i do it.Below is my xml file.
<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
...
|
by: sejal17 |
last post by:
hello
Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store that multiple worksheet data in different table.How can i do it.Below is my xml file.
<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |