Script to Import Excel File

I’m trying to import excel file into notes db with the following script: Can someone please tell me what is wrong with the code.

Sub Initialize

On Error Goto ErrorHandler

Dim session As New NotesSession

Dim db As Notesdatabase

Dim FormName As String



Set db = session.CurrentDatabase



Dim CurrentTime As String

Dim MBTitle As String

MBTitle = "Trying to Import File"



ImportFile = "" ' Name of the File

Title = "Select File"

Filter = "All Files|*.*|" 

ErrorStatus=False

Do

If NEMGetFile( 0, ImportFile, Filter, Title) <> 0 Then

location=ImportFile

If Dir$(location, 0) =“” Then

ErrorStatus=False

Else

ExcelFile = Location

End If

Else

retval2=Msgbox( “You have not selected the location of the Import File. Do you want to exit ?”,4+256,“ABORT”)

If retval2=7 Then

ErrorStatus=True

Else

Exit Sub

End If

End If

Loop Until ErrorStatus=False

Dim DownloadDoc As notesdocument

Print “Searching for the Excel file”

Set xls = GetObject(ExcelFile,“”)

Dim tmpdoc As notesdocument

Set tmpDoc = db.CreateDocument

tmpdoc.ExcelFile = ExcelFile

Const FileName$ = “@RightBack(ExcelFile ;”“\”“)”

EXFile = Evaluate(FileName$,tmpdoc)

Print “Processing the Excel file”

If Ucase$(EXFile(0)) = “UpdateUsers.xls” Then

’ Create User Profile

FormName = “UP”

currentTime = Time$()

Forall sheet In xls.Worksheets

For i = min To max

B = Trim(sheet.range(“B” & i).value)

If B =“” Then

If i = min Then

’ If Row 2, Column 2 is missing

msgdesc = “No Values to Retrieve” + Cstr(i)

Msgbox msgdesc,48,MBTitle

Exit Sub

End If

Else

’ Creating a New Order Document

Do

'This will Loop until the time is changed by atleast one second

If CurrentTime <> Time$() Then

currentTime = Time$()

Exit Do

End If

Loop

Set DownLoadDoc = db.CreateDocument

If FormName = “UP” Then

DownLoadDoc.form = FormName

DownLoadDoc.UP_GeoLocation = Trim(sheet.range(“A” & i).value)

DownLoadDoc.UP_UserRole = Trim(sheet.range(“B” & i).value)

DownLoadDoc.UP_NotesID = Trim(sheet.range(“C”& i).value)

DownLoadDoc.UP_EmailAddress = Trim(sheet.range(“D” & i).value)

Call DownLoadDoc.ComputeWithForm(True, True)

Call DownLoadDoc.Save(True, True)

End If

End If

Next

Exit Forall

End Forall

Print “Disconnecting from Excel…”

Set xls = Nothing '// Free the memory that we’d used

Print "Import has finished. "

msgdesc = "Sample Import has Finished from " + EXFile(0)

Msgbox msgdesc,48,MBTitle

Print " " '// Clear the status line

Exit Sub

ErrorHandler:

Messagebox “Error” & Str(Err) & ": " & Error$

Exit Sub

End If

End Sub

Subject: Script to Import Excel File

I wrote a similar import script which also can handle both XLS and CSV files. CSV import works much faster.

see Download

This example has a configuration profile document. So the structure of the XLS file and the notes document is not hard coded.

Subject: Script to Import Excel File

I think you need to read Andre’s post on how to post a really good question…

http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/5260e95508a2a6df8525711d00738ebf?OpenDocument

and especially

http://www-10.lotus.com/ldd/nd6forum.nsf/0/410171d83ddba6d485256df100832aba?OpenDocument

Then YOU can tell US what is wrong, and someone might be able to help.

Subject: RE: Script to Import Excel File

Please forgive me for my bad english. I’ll do my best to explan things better in the furture.

In my code, I’m able to select the excel file to impot, however, it does not create any document with the formname specified based on each row in the excel file and it does not give me error message to indicate where it is failing.

Please if you any idea what I’m trying to explain, help me!

thank you so much for your kind advice on how to post qustion.

Subject: RE: Script to Import Excel File

The first thing that stands out at me is that you are creating documents in a loop, but not saving them. Unless you save the document, you won’t see it once the program is finished.

There are plenty of other things that you could change, but that is where I’d start.

Subject: RE: Script to Import Excel File

Peter and Thomas thank you for your wonderful comments and suggestions. I just now logged on. I am goin to check out your suggestions and let you know if I succeded.

Thanks again.

Subject: RE: Script to Import Excel File

Thanks guys! Thomas your code worked fine and I was able to import the excel file into my database.

Thanks again!

Subject: Script to Import Excel File

Check this out

http://www.notessidan.se/A55B53/blogg.nsf/plink/TADN-6U8EP2

/Thomas