Export from Excel to Lotus Notes

Hi Guys, I have a problem with a Macro which exports data from Excel to a Lotus Notes Memo. A friend at another company can run it perfectly. He uses Lotus Notes 6.5.4. and i use Lotus Notes 6. 0.1.We both have the same references within the code. We have the same code. We both have Lotus Domino Objects as a reference within Excel. However, when I run it, it says “Active X component can’t create object”, on the code line “Set session = New NotesSession”.Any ideas why? here’s all the code:

Dim session As NotesSession

Dim mailDb As NotesDatabase

Dim mailDoc As NotesDocument

Dim rtItem As NotesRichTextItem

Dim dbdir As NotesDbDirectory

Dim item As NotesItem

’ Notes

’ On Error GoTo ErrorHandler

’ NotesSession = Createoleobject

’ NotesSession.ConnectTONewObject (“Notes.Notesession”)

’ Set session = CreateObject(“Lotus.NotesSession”)

'Call session.Initialize 'This get a reference to Lotus Notes

’ TextUsername = session.UserName

'This initializes the referenct

Set session = New NotesSession 'This get a reference to Lotus Notes

session.Initialize 'This initializes the referenct

'This gets a reference to the DB Directory object, which is used to find your mail file (Notes Inbox)

'The value passed as the parameter is the full Notes server name. You can find this by going to your

'Notes Inbox, selecting File → Database → Properties. The Server Name is listed under the Title.

Set dbdir = session.GetDbDirectory(“GMISM201/GMI/HSBCMERIDIAN”)

Set mailDb = dbdir.OpenMailDatabase 'This opens your mail database so you can send a message.

With mailDb

If Not .IsOpen Then 'Checking to make sure the database is open

Call mailDb.Open 'If it’s not open then open it.

End If

Set mailDoc = .CreateDocument 'Create a new document

End With

With mailDoc

'Create a field call Form and assign the value of Memo. This makes the document an e-mail message.

Set item = .AppendItemValue(“Form”, “Memo”)

Call item.CopyItemToDocument(mailDoc, “Form”) 'Add the field to the document

'Create a field called sendTo and assign the value passed in via the sendTo variable.

Set item = .AppendItemValue(“sendTo”, sendTo) 'This is the mail to list

Call item.CopyItemToDocument(mailDoc, “sendTo”)

If Len(cc) > 0 Then

'Create a field called cc and assign the value passed in via the cc variable.

Set item = .AppendItemValue(“cc”, cc) 'This is the Carbon Copy list

Call item.CopyItemToDocument(mailDoc, “cc”)

End If

If Len(bcc) > 0 Then

'Create a field called bcc and assign the value passed in via the bcc variable.

Set item = .AppendItemValue(“bcc”, bcc) 'This is the Blind Carbon Copy list

Call item.CopyItemToDocument(mailDoc, “bcc”)

End If

If Len(subject) > 0 Then

'Create a field called subject and assign the value passed in via the subject variable.

Set item = .AppendItemValue(“subject”, subject) 'This is the subject of the e-mail

Call item.CopyItemToDocument(mailDoc, “subject”)

End If

'Create a field called Body

Set rtItem = .CreateRichTextItem(“Body”)

Call rtItem.AppendText(body) 'This is the text of the e-mail

Call .Send(False)

End With

SendMailMemo = True

ExitHere:

Set item = Nothing

Set rtItem = Nothing

Set mailDoc = Nothing

Set mailDb = Nothing

Set dbdir = Nothing

Set session = Nothing

Exit Function

ErrorHandler:

Call MsgBox("Error " & Err & ": " & Error & " occurred for " & sendTo & “.”, vbExclamation, “Messaging Error”)

SendMailMemo = False

Resume ExitHere

End Function

Subject: Export from Excel to Lotus Notes

Hi Justin,

First of all, I recommend when posting code, that you remove references to your employer i.e. use a fake server name in the line that begins with:

Set dbdir = session.GetDbDirectory…

As for your problem, you might want to try the alternate method of creating a NotesSession as documented in the help at:

http://www-12.lotus.com/ldd/doc/domino_notes/6.5m2/help65_designer.nsf/f4b82fbb75e942a6852566ac0037f284/56585109e431f33085256d420050972a?OpenDocument

Dim session As NotesSession

Set session = CreateObject(“Lotus.NotesSession”)

Subject: RE: Export from Excel to Lotus Notes

Next thing he tells us is, that Justin Cutcliffe is his real name …

Subject: Export from Excel to Lotus Notes

Are you sure that Notes is registered as a COM server on your system? There was an installation problem with early versions of 6.x.x that failed to do it automatically. Try opening a command prompt, navigating to the Notes program directory and entering

regsvr32 nlsxbe.dll

Subject: RE: Export from Excel to Lotus Notes

Hi Stan,

I have nlsxbe.dll in c:\Program Files\Lotus\Notes.

However, I have tried to type “registr” but it does not

understand it.Is there another way to register it or

find out whether it is registedred or not?

Cheers,

Justin

Subject: RE: Export from Excel to Lotus Notes

Stan’s advice is correct. however there is a minor typo, it should be:

regsrv32 nlsxbe.dll

Google ‘Register dll’ and you will goet all sorts of info on what you are doing.

GL,

Shawn

Subject: RE: Export from Excel to Lotus Notes

I am a moron who can’t read. Stan had it correct the first time.Follow his post and you should be good.

Shawn

Subject: RE: Export from Excel to Lotus Notes

Here is the info from MS on how to use the tool to register the library.

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/regsvr32.mspx?mfr=true

Shawn