A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

capturing the currentuser...



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old January 9th 06, 11:26 AM posted to microsoft.public.outlook.program_vba
Martin
external usenet poster
 
Posts: 87
Default capturing the currentuser...

Thanks Eric. That's great; the only problem is that it generates a
recurrence of the old problem with the anti-virus message ("A program is
trying to access email addresses..."). Have you a solution to this (other
than changing the registry) or perhaps another way of accessing the user's
name?


"Eric Legault [MVP - Outlook]" wrote:

Try this:

Dim objNS As Outlook.NameSpace
Dim objRecip As Recipient

Set objNS = Application.GetNamespace("MAPI")
Set objRecip = objNS.CurrentUser
Debug.Print objRecip.Name & ": " & objRecip.Address

Set objNS = Nothing
Set objRecip = Nothing

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Martin" wrote:

Is there any way to return the current user's name or email address
programmatically? I know there are problems with identifying names from the
current profile in Outlook but is there a registry setting or similar (I'm
using version 2003)?

Ads
  #2  
Old January 9th 06, 04:51 PM posted to microsoft.public.outlook.program_vba
Gman
external usenet poster
 
Posts: 4
Default capturing the currentuser...

Depending on what you're trying to achieve...

You can use Environ("username") to get the *machine's* current
user/logon name - obviously it's not necessarily the same as the Outlook
namespace but if you just need a unique name for logging purposes or
something then it should do.

Martin wrote:
Thanks Eric. That's great; the only problem is that it generates a
recurrence of the old problem with the anti-virus message ("A program is
trying to access email addresses..."). Have you a solution to this (other
than changing the registry) or perhaps another way of accessing the user's
name?


"Eric Legault [MVP - Outlook]" wrote:


Try this:

Dim objNS As Outlook.NameSpace
Dim objRecip As Recipient

Set objNS = Application.GetNamespace("MAPI")
Set objRecip = objNS.CurrentUser
Debug.Print objRecip.Name & ": " & objRecip.Address

Set objNS = Nothing
Set objRecip = Nothing

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Martin" wrote:


Is there any way to return the current user's name or email address
programmatically? I know there are problems with identifying names from the
current profile in Outlook but is there a registry setting or similar (I'm
using version 2003)?

  #3  
Old January 10th 06, 04:59 PM posted to microsoft.public.outlook.program_vba
Eric Legault [MVP - Outlook]
external usenet poster
 
Posts: 830
Default capturing the currentuser...

You should not be getting that dialog at all if you are running Outlook 2003
and using the intrinsic Application object:

Microsoft Outlook "Object Model Guard" Security Issues for Developers:
http://www.outlookcode.com/d/sec.htm

You can always bypass the guard using Redemption:

http://www.dimastr.com

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Martin" wrote:

Thanks Eric. That's great; the only problem is that it generates a
recurrence of the old problem with the anti-virus message ("A program is
trying to access email addresses..."). Have you a solution to this (other
than changing the registry) or perhaps another way of accessing the user's
name?


"Eric Legault [MVP - Outlook]" wrote:

Try this:

Dim objNS As Outlook.NameSpace
Dim objRecip As Recipient

Set objNS = Application.GetNamespace("MAPI")
Set objRecip = objNS.CurrentUser
Debug.Print objRecip.Name & ": " & objRecip.Address

Set objNS = Nothing
Set objRecip = Nothing

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Martin" wrote:

Is there any way to return the current user's name or email address
programmatically? I know there are problems with identifying names from the
current profile in Outlook but is there a registry setting or similar (I'm
using version 2003)?

  #4  
Old January 11th 06, 12:03 PM posted to microsoft.public.outlook.program_vba
Martin
external usenet poster
 
Posts: 87
Default capturing the currentuser...

Yes it does seem strange but I'm using your code verbatim. It's when it hits
the objRecip.Name line that the security message pops up. I tried using the
old ActiveInspector.Session instead of GetNameSpace but it still generates
the security message.

"Eric Legault [MVP - Outlook]" wrote:

You should not be getting that dialog at all if you are running Outlook 2003
and using the intrinsic Application object:

Microsoft Outlook "Object Model Guard" Security Issues for Developers:
http://www.outlookcode.com/d/sec.htm

You can always bypass the guard using Redemption:

http://www.dimastr.com

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Martin" wrote:

Thanks Eric. That's great; the only problem is that it generates a
recurrence of the old problem with the anti-virus message ("A program is
trying to access email addresses..."). Have you a solution to this (other
than changing the registry) or perhaps another way of accessing the user's
name?


"Eric Legault [MVP - Outlook]" wrote:

Try this:

Dim objNS As Outlook.NameSpace
Dim objRecip As Recipient

Set objNS = Application.GetNamespace("MAPI")
Set objRecip = objNS.CurrentUser
Debug.Print objRecip.Name & ": " & objRecip.Address

Set objNS = Nothing
Set objRecip = Nothing

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Martin" wrote:

Is there any way to return the current user's name or email address
programmatically? I know there are problems with identifying names from the
current profile in Outlook but is there a registry setting or similar (I'm
using version 2003)?

  #5  
Old January 11th 06, 06:52 PM posted to microsoft.public.outlook.program_vba
Eric Legault [MVP - Outlook]
external usenet poster
 
Posts: 830
Default capturing the currentuser...

Are you positive you are running my code verbatim? Are you using any other
code, or have you encapsulated my code in a Sub within the ThisOutlookSession
module? This isn't in a COM Add-In, is it?

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Martin" wrote:

Yes it does seem strange but I'm using your code verbatim. It's when it hits
the objRecip.Name line that the security message pops up. I tried using the
old ActiveInspector.Session instead of GetNameSpace but it still generates
the security message.

"Eric Legault [MVP - Outlook]" wrote:

You should not be getting that dialog at all if you are running Outlook 2003
and using the intrinsic Application object:

Microsoft Outlook "Object Model Guard" Security Issues for Developers:
http://www.outlookcode.com/d/sec.htm

You can always bypass the guard using Redemption:

http://www.dimastr.com

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Martin" wrote:

Thanks Eric. That's great; the only problem is that it generates a
recurrence of the old problem with the anti-virus message ("A program is
trying to access email addresses..."). Have you a solution to this (other
than changing the registry) or perhaps another way of accessing the user's
name?


"Eric Legault [MVP - Outlook]" wrote:

Try this:

Dim objNS As Outlook.NameSpace
Dim objRecip As Recipient

Set objNS = Application.GetNamespace("MAPI")
Set objRecip = objNS.CurrentUser
Debug.Print objRecip.Name & ": " & objRecip.Address

Set objNS = Nothing
Set objRecip = Nothing

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Martin" wrote:

Is there any way to return the current user's name or email address
programmatically? I know there are problems with identifying names from the
current profile in Outlook but is there a registry setting or similar (I'm
using version 2003)?

  #6  
Old January 13th 06, 10:34 AM posted to microsoft.public.outlook.program_vba
Martin
external usenet poster
 
Posts: 87
Default capturing the currentuser...

I have encapsulated your code in the ThisOutlookSession, in the NewInspector
event. Why would this be the problem?

"Eric Legault [MVP - Outlook]" wrote:

Are you positive you are running my code verbatim? Are you using any other
code, or have you encapsulated my code in a Sub within the ThisOutlookSession
module? This isn't in a COM Add-In, is it?

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Martin" wrote:

Yes it does seem strange but I'm using your code verbatim. It's when it hits
the objRecip.Name line that the security message pops up. I tried using the
old ActiveInspector.Session instead of GetNameSpace but it still generates
the security message.

"Eric Legault [MVP - Outlook]" wrote:

You should not be getting that dialog at all if you are running Outlook 2003
and using the intrinsic Application object:

Microsoft Outlook "Object Model Guard" Security Issues for Developers:
http://www.outlookcode.com/d/sec.htm

You can always bypass the guard using Redemption:

http://www.dimastr.com

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Martin" wrote:

Thanks Eric. That's great; the only problem is that it generates a
recurrence of the old problem with the anti-virus message ("A program is
trying to access email addresses..."). Have you a solution to this (other
than changing the registry) or perhaps another way of accessing the user's
name?


"Eric Legault [MVP - Outlook]" wrote:

Try this:

Dim objNS As Outlook.NameSpace
Dim objRecip As Recipient

Set objNS = Application.GetNamespace("MAPI")
Set objRecip = objNS.CurrentUser
Debug.Print objRecip.Name & ": " & objRecip.Address

Set objNS = Nothing
Set objRecip = Nothing

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Martin" wrote:

Is there any way to return the current user's name or email address
programmatically? I know there are problems with identifying names from the
current profile in Outlook but is there a registry setting or similar (I'm
using version 2003)?

  #7  
Old January 13th 06, 04:46 PM posted to microsoft.public.outlook.program_vba
Eric Legault [MVP - Outlook]
external usenet poster
 
Posts: 830
Default capturing the currentuser...

You seem to be doing everything right. I'm stumped. Maybe post all your
code just to see if I can find something strange?

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Martin" wrote:

I have encapsulated your code in the ThisOutlookSession, in the NewInspector
event. Why would this be the problem?

"Eric Legault [MVP - Outlook]" wrote:

Are you positive you are running my code verbatim? Are you using any other
code, or have you encapsulated my code in a Sub within the ThisOutlookSession
module? This isn't in a COM Add-In, is it?

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Martin" wrote:

Yes it does seem strange but I'm using your code verbatim. It's when it hits
the objRecip.Name line that the security message pops up. I tried using the
old ActiveInspector.Session instead of GetNameSpace but it still generates
the security message.

"Eric Legault [MVP - Outlook]" wrote:

You should not be getting that dialog at all if you are running Outlook 2003
and using the intrinsic Application object:

Microsoft Outlook "Object Model Guard" Security Issues for Developers:
http://www.outlookcode.com/d/sec.htm

You can always bypass the guard using Redemption:

http://www.dimastr.com

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Martin" wrote:

Thanks Eric. That's great; the only problem is that it generates a
recurrence of the old problem with the anti-virus message ("A program is
trying to access email addresses..."). Have you a solution to this (other
than changing the registry) or perhaps another way of accessing the user's
name?


"Eric Legault [MVP - Outlook]" wrote:

Try this:

Dim objNS As Outlook.NameSpace
Dim objRecip As Recipient

Set objNS = Application.GetNamespace("MAPI")
Set objRecip = objNS.CurrentUser
Debug.Print objRecip.Name & ": " & objRecip.Address

Set objNS = Nothing
Set objRecip = Nothing

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Martin" wrote:

Is there any way to return the current user's name or email address
programmatically? I know there are problems with identifying names from the
current profile in Outlook but is there a registry setting or similar (I'm
using version 2003)?

  #8  
Old January 17th 06, 11:56 AM posted to microsoft.public.outlook.program_vba
Martin
external usenet poster
 
Posts: 87
Default capturing the currentuser...

Thanks for taking the time Eric. I'll include the relevant procedures below.
Just to explain, in our organisation users use two mailboxes within Exchange
for work they do for two different parts of the company - this involves two
separate email addresses and matching user names (as they appear on the GAL)
with or without "(Ltd)" at the end. Everyone's prompted for one of two
profiles when they enter Outlook but, because of potential errors, we still
want to be sure everyone is prompted again for the From address when they
create a new message (or reply or forward). Sadly the Accounts button that
works so well with separate SMTP accounts doesn't seem to be available for
mailboxes within the same server (if I'm missing something, please let me
know!).

Two other things (if you have the time!):
There's a matching signature for each mailbox and I'm currently including
that at the end of the process using the CurrentItem_Send event. I would
prefer to do this at the start of a new message but can't see an easy way to
swap to the other signature if the user then changes their mind as to whom
the message is from. Also, I can't say I'm proud of the series of SendKeys
statements at the end but, in the absence of the Dialogs collection, I'm at a
loss to finding a neater way to get into the From list!

Option Explicit
Public WithEvents myInspectors As Outlook.Inspectors
Public WithEvents CurrentInspector As Outlook.Inspector
Public WithEvents CurrentItem As Outlook.MailItem
Dim profUserName As String
Dim aUserName As String
Dim bUserName As String

Private Sub Application_Startup()
Set myInspectors = Application.Inspectors
End Sub

Private Sub myInspectors_NewInspector(ByVal Inspector As Outlook.Inspector)
On Error GoTo handler
Dim myMail As Outlook.MailItem
Dim objNS As Outlook.NameSpace
Dim objRecip As Recipient

'checks this is a new mail message
If Not TypeOf Inspector.CurrentItem Is Outlook.MailItem Then Exit Sub
Set CurrentInspector = Inspector
Set myMail = CurrentInspector.CurrentItem
Set CurrentItem = myMail
If myMail.Sent Or myMail.Parent = "Drafts" Then Exit Sub

'obtains default user name and creates A and B versions
Set objNS = Application.GetNamespace("MAPI")
Set objRecip = objNS.CurrentUser
profUserName = objRecip.Name

If InStr(1, profUserName, " (Ltd)") = 0 Then
aUserName = profUserName
Else
aUserName = Left(profUserName, InStr(1, profUserName, " (Ltd)") - 1)
End If
bUserName = aUserName & " (Ltd)"

'activates "From" button and narrows address list down to names that match
user
SendKeys "%r"
SendKeys "%v"
SendKeys "{down 3}"
SendKeys "{enter}"
SendKeys aUserName
SendKeys "{enter}"

Set myMail = Nothing
Set objNS = Nothing
Set objRecip = Nothing

Exit Sub

handler:
If Err.Number = 287 Then 'if user clicks "No" to Outlook security
message
MsgBox "Tick 'Allow access for 1 minute' and then click on 'Yes' so
that Outlook can look up your name", vbCritical
Resume
Else
MsgBox Err.Number & " " & Err.Description
End If

End Sub


"Eric Legault [MVP - Outlook]" wrote:

You seem to be doing everything right. I'm stumped. Maybe post all your
code just to see if I can find something strange?

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Martin" wrote:

I have encapsulated your code in the ThisOutlookSession, in the NewInspector
event. Why would this be the problem?

"Eric Legault [MVP - Outlook]" wrote:

Are you positive you are running my code verbatim? Are you using any other
code, or have you encapsulated my code in a Sub within the ThisOutlookSession
module? This isn't in a COM Add-In, is it?

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Martin" wrote:

Yes it does seem strange but I'm using your code verbatim. It's when it hits
the objRecip.Name line that the security message pops up. I tried using the
old ActiveInspector.Session instead of GetNameSpace but it still generates
the security message.

"Eric Legault [MVP - Outlook]" wrote:

You should not be getting that dialog at all if you are running Outlook 2003
and using the intrinsic Application object:

Microsoft Outlook "Object Model Guard" Security Issues for Developers:
http://www.outlookcode.com/d/sec.htm

You can always bypass the guard using Redemption:

http://www.dimastr.com

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Martin" wrote:

Thanks Eric. That's great; the only problem is that it generates a
recurrence of the old problem with the anti-virus message ("A program is
trying to access email addresses..."). Have you a solution to this (other
than changing the registry) or perhaps another way of accessing the user's
name?


"Eric Legault [MVP - Outlook]" wrote:

Try this:

Dim objNS As Outlook.NameSpace
Dim objRecip As Recipient

Set objNS = Application.GetNamespace("MAPI")
Set objRecip = objNS.CurrentUser
Debug.Print objRecip.Name & ": " & objRecip.Address

Set objNS = Nothing
Set objRecip = Nothing

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Martin" wrote:

Is there any way to return the current user's name or email address
programmatically? I know there are problems with identifying names from the
current profile in Outlook but is there a registry setting or similar (I'm
using version 2003)?

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Capturing a "Paste" Event Neil Dittmar Outlook - Using Forms 0 February 1st 06 10:46 PM
Capturing Message URL Avatar Outlook Express 7 January 30th 06 06:47 PM


All times are GMT +1. The time now is 08:26 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.