Domino Code Fragment

Code Name*
Import from Excel
Date*
08/17/2000
Source (or email address if you prefer)*
Anonymous
IP address:.199.90.101.212
Description*
Import excel Spreadsheet into a view and will update the phone number is the document already exists
Type*
LotusScript
Categories*
File Input/Output
Implementation:
Modify code
Required Client:
(none)
Server:
(none)
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
Sub Initialize
Dim xlFilename As String
xlFilename = Inputbox$("Please enter the complete Drive\Path\FileName.XLS for the file you wish to Import.", "Enter Import File Information", "D:\State\wake2.xls") '// This is the name of the Excel file that will be imported
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Set db = session.CurrentDatabase
Dim row As Integer
Dim written As Integer
Dim number As Integer
number = Inputbox$("Please enter the number of rows in spreadsheet", "Enter the Number of Rows in the Speadsheet") '//Start import of Excel file
Dim Excel As Variant
Dim xlWorkbook As Variant
Dim xlSheet As Variant
Dim xlCells As Variant
Print "Connecting to Excel..."
Set Excel = CreateObject("excel.application")
Excel.Visible = False '// Don't display the Excel window
Print "Opening " & xlFilename & "..."
Excel.Workbooks.Open xlFilename '// Open the Excel file
Set xlWorkbook = Excel.ActiveWorkbook
Set xlSheet = xlWorkbook.ActiveSheet
Set xlCells = xlSheet.Cells
row = 0
written = 0
Print "Starting import from Excel file..."
Dim strName As String
Add:
row = row + 1
written=written+1
Print ("Importing row: "& Cstr(row) & " of: " &Cstr(number))'//prints the number of the record being imported
Set view = db.GetView("By Facility")
strName = xlCells( row, 1). Value
Set doc = view.GetDocumentByKey(strName ,True)
If doc Is Nothing Then
Set doc = db.CreateDocument
With doc
.Form = "New Document"
.Name = strName
.Street = xlCells(row, 2).Value
.City = xlCells( row, 3 ).Value
.Zip = xlCells(row, 4).Value
.phone = xlCells( row, 5).Value
.FacType=xlCells( row, 6).Value
End With
Else
Call doc.replaceitemvalue("phone", xlCells(row, 5).Value)
End If
Call doc.Save( True, True ) '// Save the new doc
Set doc = Nothing
If written < number Then Goto Add
Print "Disconnecting from Excel.."
excel.quit
End Sub