Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Retrieving values from existing worksheet

I am trying to convert a program that worked well in Visual Basic 6 to the
..net version of Visual Basic. I am attempting to get a value from a cell in
an existing worksheet, but I am unable to do so. I get an error, "Exception
from HRESULT: 0x800A03EC", every way that I have tried. It fails attempting
to set temp2. The code is simple and the answer must be too, but it escapes
me. Here is the code:

Imports Microsoft.Office.Interop.Excel
Imports System.IO
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim returnFile As String = "C:\MyPool\MyPoolData\Test.xls"
Dim curFile As String = "c:\MyPool\MyPoolData\OBGSchedule.xls"
Dim temp, temp2 As String

Dim xla As New Application

Dim xlb As Workbook

Dim xls As New Worksheet
Dim xlsData As New Worksheet

xlb = xla.Workbooks.Add
xls = CType(xlb.Worksheets.Add, Worksheet)
xlsData = CType(xlb.Worksheets.Add, Worksheet)
'Dim xlr As Range

xls.Activate()
xlsData.Activate()

xlb = xla.Workbooks.Open(curFile)
xls = CType(xlb.Worksheets("Sheet1"), Worksheet)
xlsData = CType(xlb.Worksheets("Data"), Worksheet)

For Each ws As Worksheet In xlb.Worksheets
temp = ws.Name
temp2 = (ws.Range(ws.Cells(6, 2)).Value).ToString
Next

For Each ws As Worksheet In xlb.Sheets
temp = ws.Name
temp2 = (ws.Range(ws.Cells(6, 2)).Value).ToString
Next

'xlb.SaveAs(returnFile, FileFormat:=XlFileFormat.xlWorkbookNormal)
xlb.Close(SaveChanges:=False)
xla.Quit()

End Sub
End Class
--
The Villages Bill
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 298
Default Retrieving values from existing worksheet

Maybe there's something here which might help:
http://support.microsoft.com/kb/302094

I'm not clear on why you assign "xlb" and "xlData" twice, but don't use the
first assignment ?

Tim


"TheVillagesBill" wrote in message
...
I am trying to convert a program that worked well in Visual Basic 6 to the
.net version of Visual Basic. I am attempting to get a value from a cell
in
an existing worksheet, but I am unable to do so. I get an error,
"Exception
from HRESULT: 0x800A03EC", every way that I have tried. It fails
attempting
to set temp2. The code is simple and the answer must be too, but it
escapes
me. Here is the code:

Imports Microsoft.Office.Interop.Excel
Imports System.IO
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim returnFile As String = "C:\MyPool\MyPoolData\Test.xls"
Dim curFile As String = "c:\MyPool\MyPoolData\OBGSchedule.xls"
Dim temp, temp2 As String

Dim xla As New Application

Dim xlb As Workbook

Dim xls As New Worksheet
Dim xlsData As New Worksheet

xlb = xla.Workbooks.Add
xls = CType(xlb.Worksheets.Add, Worksheet)
xlsData = CType(xlb.Worksheets.Add, Worksheet)
'Dim xlr As Range

xls.Activate()
xlsData.Activate()

xlb = xla.Workbooks.Open(curFile)
xls = CType(xlb.Worksheets("Sheet1"), Worksheet)
xlsData = CType(xlb.Worksheets("Data"), Worksheet)

For Each ws As Worksheet In xlb.Worksheets
temp = ws.Name
temp2 = (ws.Range(ws.Cells(6, 2)).Value).ToString
Next

For Each ws As Worksheet In xlb.Sheets
temp = ws.Name
temp2 = (ws.Range(ws.Cells(6, 2)).Value).ToString
Next

'xlb.SaveAs(returnFile, FileFormat:=XlFileFormat.xlWorkbookNormal)
xlb.Close(SaveChanges:=False)
xla.Quit()

End Sub
End Class
--
The Villages Bill



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Retrieving values from existing worksheet

I modified the code as follows and I don't get an exception, but the value
assigned to temp 2 is "System.__ComObject" as a string. Code follows:


Imports Microsoft.Office.Interop.Excel
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim curFile As String = "c:\MyPool\MyPoolData\OBGSchedule.xls"
Dim temp, temp2 As String

Dim xla As New Application
'Dim xlb As Workbook
'Dim xls As New Worksheet
Dim xlb = xla.Workbooks.Add
xlb.Activate()
For Each ws As Worksheet In xlb.Worksheets
ws.Activate()
temp = ws.Name
temp2 = ws.Cells(6, 2).ToString
Next

xlb.Close(SaveChanges:=False)
xla.Quit()


End Sub
End Class
--
The Villages Bill


"Tim Williams" wrote:

Maybe there's something here which might help:
http://support.microsoft.com/kb/302094

I'm not clear on why you assign "xlb" and "xlData" twice, but don't use the
first assignment ?

Tim


"TheVillagesBill" wrote in message
...
I am trying to convert a program that worked well in Visual Basic 6 to the
.net version of Visual Basic. I am attempting to get a value from a cell
in
an existing worksheet, but I am unable to do so. I get an error,
"Exception
from HRESULT: 0x800A03EC", every way that I have tried. It fails
attempting
to set temp2. The code is simple and the answer must be too, but it
escapes
me. Here is the code:

Imports Microsoft.Office.Interop.Excel
Imports System.IO
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim returnFile As String = "C:\MyPool\MyPoolData\Test.xls"
Dim curFile As String = "c:\MyPool\MyPoolData\OBGSchedule.xls"
Dim temp, temp2 As String

Dim xla As New Application

Dim xlb As Workbook

Dim xls As New Worksheet
Dim xlsData As New Worksheet

xlb = xla.Workbooks.Add
xls = CType(xlb.Worksheets.Add, Worksheet)
xlsData = CType(xlb.Worksheets.Add, Worksheet)
'Dim xlr As Range

xls.Activate()
xlsData.Activate()

xlb = xla.Workbooks.Open(curFile)
xls = CType(xlb.Worksheets("Sheet1"), Worksheet)
xlsData = CType(xlb.Worksheets("Data"), Worksheet)

For Each ws As Worksheet In xlb.Worksheets
temp = ws.Name
temp2 = (ws.Range(ws.Cells(6, 2)).Value).ToString
Next

For Each ws As Worksheet In xlb.Sheets
temp = ws.Name
temp2 = (ws.Range(ws.Cells(6, 2)).Value).ToString
Next

'xlb.SaveAs(returnFile, FileFormat:=XlFileFormat.xlWorkbookNormal)
xlb.Close(SaveChanges:=False)
xla.Quit()

End Sub
End Class
--
The Villages Bill



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 298
Default Retrieving values from existing worksheet

Try:

temp2 = ws.Cells(6, 2).Value.ToString

In VBA you can get away by relying on default properties like Value: not
sure if that's also the case in VB.NET


Tim

"TheVillagesBill" wrote in message
...
I modified the code as follows and I don't get an exception, but the value
assigned to temp 2 is "System.__ComObject" as a string. Code follows:


Imports Microsoft.Office.Interop.Excel
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim curFile As String = "c:\MyPool\MyPoolData\OBGSchedule.xls"
Dim temp, temp2 As String

Dim xla As New Application
'Dim xlb As Workbook
'Dim xls As New Worksheet
Dim xlb = xla.Workbooks.Add
xlb.Activate()
For Each ws As Worksheet In xlb.Worksheets
ws.Activate()
temp = ws.Name
temp2 = ws.Cells(6, 2).ToString
Next

xlb.Close(SaveChanges:=False)
xla.Quit()


End Sub
End Class
--
The Villages Bill


"Tim Williams" wrote:

Maybe there's something here which might help:
http://support.microsoft.com/kb/302094

I'm not clear on why you assign "xlb" and "xlData" twice, but don't use
the
first assignment ?

Tim


"TheVillagesBill" wrote in message
...
I am trying to convert a program that worked well in Visual Basic 6 to
the
.net version of Visual Basic. I am attempting to get a value from a
cell
in
an existing worksheet, but I am unable to do so. I get an error,
"Exception
from HRESULT: 0x800A03EC", every way that I have tried. It fails
attempting
to set temp2. The code is simple and the answer must be too, but it
escapes
me. Here is the code:

Imports Microsoft.Office.Interop.Excel
Imports System.IO
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim returnFile As String = "C:\MyPool\MyPoolData\Test.xls"
Dim curFile As String = "c:\MyPool\MyPoolData\OBGSchedule.xls"
Dim temp, temp2 As String

Dim xla As New Application

Dim xlb As Workbook

Dim xls As New Worksheet
Dim xlsData As New Worksheet

xlb = xla.Workbooks.Add
xls = CType(xlb.Worksheets.Add, Worksheet)
xlsData = CType(xlb.Worksheets.Add, Worksheet)
'Dim xlr As Range

xls.Activate()
xlsData.Activate()

xlb = xla.Workbooks.Open(curFile)
xls = CType(xlb.Worksheets("Sheet1"), Worksheet)
xlsData = CType(xlb.Worksheets("Data"), Worksheet)

For Each ws As Worksheet In xlb.Worksheets
temp = ws.Name
temp2 = (ws.Range(ws.Cells(6, 2)).Value).ToString
Next

For Each ws As Worksheet In xlb.Sheets
temp = ws.Name
temp2 = (ws.Range(ws.Cells(6, 2)).Value).ToString
Next

'xlb.SaveAs(returnFile,
FileFormat:=XlFileFormat.xlWorkbookNormal)
xlb.Close(SaveChanges:=False)
xla.Quit()

End Sub
End Class
--
The Villages Bill



.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Retrieving values from existing worksheet

Nope, I tried that, but .value is not included in the intellisense selection
window. It won't compile.
--
The Villages Bill


"Tim Williams" wrote:

Try:

temp2 = ws.Cells(6, 2).Value.ToString

In VBA you can get away by relying on default properties like Value: not
sure if that's also the case in VB.NET


Tim

"TheVillagesBill" wrote in message
...
I modified the code as follows and I don't get an exception, but the value
assigned to temp 2 is "System.__ComObject" as a string. Code follows:


Imports Microsoft.Office.Interop.Excel
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim curFile As String = "c:\MyPool\MyPoolData\OBGSchedule.xls"
Dim temp, temp2 As String

Dim xla As New Application
'Dim xlb As Workbook
'Dim xls As New Worksheet
Dim xlb = xla.Workbooks.Add
xlb.Activate()
For Each ws As Worksheet In xlb.Worksheets
ws.Activate()
temp = ws.Name
temp2 = ws.Cells(6, 2).ToString
Next

xlb.Close(SaveChanges:=False)
xla.Quit()


End Sub
End Class
--
The Villages Bill


"Tim Williams" wrote:

Maybe there's something here which might help:
http://support.microsoft.com/kb/302094

I'm not clear on why you assign "xlb" and "xlData" twice, but don't use
the
first assignment ?

Tim


"TheVillagesBill" wrote in message
...
I am trying to convert a program that worked well in Visual Basic 6 to
the
.net version of Visual Basic. I am attempting to get a value from a
cell
in
an existing worksheet, but I am unable to do so. I get an error,
"Exception
from HRESULT: 0x800A03EC", every way that I have tried. It fails
attempting
to set temp2. The code is simple and the answer must be too, but it
escapes
me. Here is the code:

Imports Microsoft.Office.Interop.Excel
Imports System.IO
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim returnFile As String = "C:\MyPool\MyPoolData\Test.xls"
Dim curFile As String = "c:\MyPool\MyPoolData\OBGSchedule.xls"
Dim temp, temp2 As String

Dim xla As New Application

Dim xlb As Workbook

Dim xls As New Worksheet
Dim xlsData As New Worksheet

xlb = xla.Workbooks.Add
xls = CType(xlb.Worksheets.Add, Worksheet)
xlsData = CType(xlb.Worksheets.Add, Worksheet)
'Dim xlr As Range

xls.Activate()
xlsData.Activate()

xlb = xla.Workbooks.Open(curFile)
xls = CType(xlb.Worksheets("Sheet1"), Worksheet)
xlsData = CType(xlb.Worksheets("Data"), Worksheet)

For Each ws As Worksheet In xlb.Worksheets
temp = ws.Name
temp2 = (ws.Range(ws.Cells(6, 2)).Value).ToString
Next

For Each ws As Worksheet In xlb.Sheets
temp = ws.Name
temp2 = (ws.Range(ws.Cells(6, 2)).Value).ToString
Next

'xlb.SaveAs(returnFile,
FileFormat:=XlFileFormat.xlWorkbookNormal)
xlb.Close(SaveChanges:=False)
xla.Quit()

End Sub
End Class
--
The Villages Bill


.



.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 298
Default Retrieving values from existing worksheet

All of the MS examples I've seen use the .Value property, so it's a bit
strange your code won't even compile with it.

Tim


"TheVillagesBill" wrote in message
...
Nope, I tried that, but .value is not included in the intellisense
selection
window. It won't compile.
--
The Villages Bill


"Tim Williams" wrote:

Try:

temp2 = ws.Cells(6, 2).Value.ToString

In VBA you can get away by relying on default properties like Value: not
sure if that's also the case in VB.NET


Tim

"TheVillagesBill" wrote in message
...
I modified the code as follows and I don't get an exception, but the
value
assigned to temp 2 is "System.__ComObject" as a string. Code follows:


Imports Microsoft.Office.Interop.Excel
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim curFile As String = "c:\MyPool\MyPoolData\OBGSchedule.xls"
Dim temp, temp2 As String

Dim xla As New Application
'Dim xlb As Workbook
'Dim xls As New Worksheet
Dim xlb = xla.Workbooks.Add
xlb.Activate()
For Each ws As Worksheet In xlb.Worksheets
ws.Activate()
temp = ws.Name
temp2 = ws.Cells(6, 2).ToString
Next

xlb.Close(SaveChanges:=False)
xla.Quit()


End Sub
End Class
--
The Villages Bill


"Tim Williams" wrote:

Maybe there's something here which might help:
http://support.microsoft.com/kb/302094

I'm not clear on why you assign "xlb" and "xlData" twice, but don't
use
the
first assignment ?

Tim


"TheVillagesBill" wrote in message
...
I am trying to convert a program that worked well in Visual Basic 6
to
the
.net version of Visual Basic. I am attempting to get a value from a
cell
in
an existing worksheet, but I am unable to do so. I get an error,
"Exception
from HRESULT: 0x800A03EC", every way that I have tried. It fails
attempting
to set temp2. The code is simple and the answer must be too, but it
escapes
me. Here is the code:

Imports Microsoft.Office.Interop.Excel
Imports System.IO
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As
System.EventArgs) Handles Button1.Click
Dim returnFile As String = "C:\MyPool\MyPoolData\Test.xls"
Dim curFile As String =
"c:\MyPool\MyPoolData\OBGSchedule.xls"
Dim temp, temp2 As String

Dim xla As New Application

Dim xlb As Workbook

Dim xls As New Worksheet
Dim xlsData As New Worksheet

xlb = xla.Workbooks.Add
xls = CType(xlb.Worksheets.Add, Worksheet)
xlsData = CType(xlb.Worksheets.Add, Worksheet)
'Dim xlr As Range

xls.Activate()
xlsData.Activate()

xlb = xla.Workbooks.Open(curFile)
xls = CType(xlb.Worksheets("Sheet1"), Worksheet)
xlsData = CType(xlb.Worksheets("Data"), Worksheet)

For Each ws As Worksheet In xlb.Worksheets
temp = ws.Name
temp2 = (ws.Range(ws.Cells(6, 2)).Value).ToString
Next

For Each ws As Worksheet In xlb.Sheets
temp = ws.Name
temp2 = (ws.Range(ws.Cells(6, 2)).Value).ToString
Next

'xlb.SaveAs(returnFile,
FileFormat:=XlFileFormat.xlWorkbookNormal)
xlb.Close(SaveChanges:=False)
xla.Quit()

End Sub
End Class
--
The Villages Bill


.



.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create Worksheet From Values in Existing Cells Using Existing Worksheet as Template. Ardy Excel Programming 18 November 29th 06 03:23 AM
Help with Comparing values and retrieving values in Excel!!!!!! [email protected] Excel Worksheet Functions 1 November 17th 06 12:21 AM
retrieving values from a specified sheet Anift Excel Worksheet Functions 4 April 1st 06 01:14 PM
Retrieving VLookup Values xander1987 Excel Programming 1 September 14th 05 11:32 AM
Help Retrieving Cell Values Marshall Excel Programming 1 October 28th 03 05:32 PM


All times are GMT +1. The time now is 11:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"