Import from Excel - what's wrong with this code?

Hi there,

i have an excel sheet with only the first column populated with some value (windows file path) that i want to import into a text field in a database. I want to go as far as the 1465th row.

I created an agent with the following code. At first the code ran but it did not populate the values from excel file - strangely it seems to have copied the value of another field within the document. Some of the cells are blank (no file path specified) - so it showed ‘None listed’ there - which again seems to be a value taken from another field in the same document. It appears as though it filled these values after it failed to get them from excel file.

Now when i tried to run the same code (no changes made), i get ‘type mismatch’ error … since this is a test database, i deleted all the documents and then copied them again from the parent database - still get the error.

Thanks for all your help!

Ayaz

Sub Initialize

Dim s As New NotesSession

Dim ws As New NotesUIWorkspace

Dim db As NotesDatabase

Dim view As NotesView

Dim doc As NotesDocument

Dim row As Integer

Dim xlFileName As Variant

Dim Excel As Variant

Dim xlWorkBook As Variant

Dim xlSheet As Variant

Dim xlCell As Variant



Set db = s.CurrentDatabase

xlFileName = "C:\Documents and Settings\abcd\parts.xls"



Set Excel = createObject("excel.Application")

Excel.visible = False

Excel.workbooks.open xlFileName

Set xlWorkBook = Excel.ActiveWorkBook

Set xlSheet = xlWorkBook.ActiveSheet

Set xlCell = xlSheet.cells



Set view = db.getview("<view name>")

Set doc = view.GetFirstDocument

row=1

Do While Not (doc Is Nothing)

	doc.<field name> = xlCell(row,1).value

	Call doc.Save( True, True )

	Set doc = view.GetNextDocument(doc)

	row=row+1

	If row > 1465 Then 	Exit Do

Loop

Excel.Quit

End Sub

Subject: Import from Excel - what’s wrong with this code?

I have tested your code and got results as expected.

I think your problem lies with your data. Try to run a test with an XLS-file with some “flat” text data. If that runs, I have proven my point.

Subject: RE: Import from Excel - what’s wrong with this code?

Yep, test with a simple Excel sheet created from scratch by yourself. Columns in Excel can have an attribute “isVeryHidden” (or something like that) which will not only hide them from the UI, but also make the column sorting skip them. So, even if you look at an Excel file with columns A B C D and so on, there could be other columns in between of in front of A. However, when accessing this sheet programmatically, the hidden columns ARE recognized.

Could be something different, but this is something I have learned to watch out for the hard way.

Subject: Import from Excel - what’s wrong with this code?

Thanks guys!

I copied the data into a new excel file- and away we go!