I am creating an Excel spreadsheet from VB.net. The program populates some cells of the spreadsheet. The user can also enter data into cells. These two activities can happen consecutively (not concurrently).

If the user does not hit ENTER after entering their data, VB.net cannot regain control of Excel. Is there a way around this

Below is a short test stub that demonstrates this. The user enters a number into cell A1. After he does this, the user hits ok to the msgbox. The square of the number goes into A2. If the user does not hit enter after typing in their number, a HRESULT: 0x800A03EC error occurs.

Any help appreciated,

Fred

Sub Main()

Dim excel As Excel.Application

Dim wb As Excel.Workbook

Dim sheet As Excel.Worksheet

Dim data3 As Integer

Dim rng As Excel.Range

excel = New Excel.Application

wb = excel.Workbooks.Add

sheet = CType(wb.Worksheets.Add, Microsoft.Office.Interop.Excel.Worksheet)

excel.Visible = True

wb.Activate()

rng = sheet.Range("A1")

MsgBox("enter number in cell A1")

data3 = CInt(rng.Value)

Do While data3 <> 100

rng = sheet.Range("A2")

rng.Value = data3 * data3

rng = sheet.Range("A1")

MsgBox("enter number in cell A1")

data3 = CInt(rng.Value)

Loop

End Sub