Function problem when I publish

C

Curtis Fowler

I used the Function GetMailboxUserName() on page 233, Listing 12.8 from the
book Microsoft Outlook Programming. I added
Sub MailUser()
MsgBox "The Initiator is " & GetMailboxUserName(initiator)
End Sub
& tried it in the VbaProject.OTM module. Seems to work great. When I
copy/paste it into a blank Script Editor on a Task Form & publish it to the
Exchange Server Public Folder, it gives me an error " Expected end of
statement Line number 29."
That line is Dim objApp As Outlook.Application
It gives the same error with Outlook 2002 & 2003. My Inbox is on the
Exchange Serverby default. Any ideas?
 
S

Sue Mosher [MVP-Outlook]

That version is for VBA. The version in listing 20.7 is for VBScript. You'll
probably learn a lot by comparing them.
 
C

Curtis Fowler

Here's what I put in the Script Editor & published it:

Call MailUser
Sub MailUser()
MsgBox "The Initiator is " & GetMailboxUserName(initiator)
End Sub
Function GetMailboxUserName(mailbox)
Dim objNS
Dim objInbox
Dim strName
Dim intPos
Set objNS = Application.GetNameSpace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
strName = objInbox.Parent.Name
intPos = InStr(1, strName, "Mailbox - ", vbTextCompare)
If intPos > 0 Then
GetMailboxUserName = Right(strName, intPos + 9)
End If
Set objInbox = Nothing
Set objNS = Nothing
End Function

When I run it I get a Script Error Line 10 which is Set objNS = ...
I've looked at every MS reference page & can't find anything wrong with the
structure of any of the code. Sorry but I'm stuck again. Thanks.

Sue Mosher said:
That version is for VBA. The version in listing 20.7 is for VBScript. You'll
probably learn a lot by comparing them.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

Sue Mosher [MVP-Outlook]

I don't know why the Application.GetNamespace statement would fail, but you
can't use olFolderInbox in VBScript unless you have a Const declaration for
it somewhere. Also use Mid instead of Right to get the name:

GetMailboxUserName = Mid(strName, intPos + 9)

Also, I can't see that you're using a proper event handler to call this
code. Put a command button on your form and put your Call MailUser in it:

Sub CommandButton1_Click()
Call MailUser
End Sub

Click the button to test.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



Curtis Fowler said:
Here's what I put in the Script Editor & published it:

Call MailUser
Sub MailUser()
MsgBox "The Initiator is " & GetMailboxUserName(initiator)
End Sub
Function GetMailboxUserName(mailbox)
Dim objNS
Dim objInbox
Dim strName
Dim intPos
Set objNS = Application.GetNameSpace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
strName = objInbox.Parent.Name
intPos = InStr(1, strName, "Mailbox - ", vbTextCompare)
If intPos > 0 Then
GetMailboxUserName = Right(strName, intPos + 9)
End If
Set objInbox = Nothing
Set objNS = Nothing
End Function

When I run it I get a Script Error Line 10 which is Set objNS = ...
I've looked at every MS reference page & can't find anything wrong with
the
structure of any of the code. Sorry but I'm stuck again. Thanks.
 
C

Curtis Fowler

I tried using the index (6) instead of (olFolderInbox) but still got the error.
I'll try adding a button to see what it does. Thanks.
 
C

Curtis Fowler

It likes it working from a Cmd button. No errors at all. Thanks for all your
help Sue!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top