Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Grab Open Outlook Username from Excel

I want to grab the users Outlook Email address while an Excel Macro is
running (and assuming Outlook is also running on the machine). Is there a
quick and dirty way of doing this? If so, please point me in the right
direction.

Thanks!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Grab Open Outlook Username from Excel

Not so easy

See this site for code
http://vbnet.mvps.org/


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"jayklmno" wrote in message ...
I want to grab the users Outlook Email address while an Excel Macro is
running (and assuming Outlook is also running on the machine). Is there a
quick and dirty way of doing this? If so, please point me in the right
direction.

Thanks!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Grab Open Outlook Username from Excel

Figured it out for myself...

Sub DisplayCurrentUser()
Dim myolApp As Outlook.Application
Dim myNamespace As Outlook.Namespace
Set myolApp = CreateObject("Outlook.Application")
Set myNamespace = myolApp.GetNamespace("MAPI")
MsgBox myNamespace.CurrentUser
End Sub

Only trouble is it prompts the Outlook Security pop box.

"jayklmno" wrote:

I want to grab the users Outlook Email address while an Excel Macro is
running (and assuming Outlook is also running on the machine). Is there a
quick and dirty way of doing this? If so, please point me in the right
direction.

Thanks!


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 897
Default Grab Open Outlook Username from Excel

If you wanted to avoid the security prompt, a sneaky way to get the current
user name is to parse the text string in the name of the default mailbox. It
would always (usually) contain the name of the person who is setup for that
copy of Outlook. In this example, a Msgbox appears with the name of the
current user. You would need to use Instr and/or Mid to parse out the actual
person's name.

Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Application.StatusBar = "Checking For Existing Copy of Outlook..."
' test for instance of Outlook, exit if not able to start one
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If Err.Number < 0 Then
Set olApp = CreateObject("Outlook.Application")
End If
On Error GoTo 0

If olApp Is Nothing Then
Application.StatusBar = False
MsgBox "Cannot start Outlook. Please open Outlook and try again.", _
vbInformation
Exit Sub
End If

Set objNS = olApp.GetNamespace("MAPI")

Msgbox objNS.GetDefaultFolder(olFolderInbox).Parent

Set objNS = Nothing
Set olApp = Nothing
End Sub

On my system I would get a message box stating "Mailbox - Jimmy Pena" it
would then be a simple matter of extracting my name from this string.

This is "air code" from memory so you should proof it first before running.

HTH,
JP

"jayklmno" wrote:

Figured it out for myself...

Sub DisplayCurrentUser()
Dim myolApp As Outlook.Application
Dim myNamespace As Outlook.Namespace
Set myolApp = CreateObject("Outlook.Application")
Set myNamespace = myolApp.GetNamespace("MAPI")
MsgBox myNamespace.CurrentUser
End Sub

Only trouble is it prompts the Outlook Security pop box.

"jayklmno" wrote:

I want to grab the users Outlook Email address while an Excel Macro is
running (and assuming Outlook is also running on the machine). Is there a
quick and dirty way of doing this? If so, please point me in the right
direction.

Thanks!


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to open Excel in different windows AND open from Outlook? KimD Setting up and Configuration of Excel 0 January 25th 10 07:47 PM
How to get username during workbooks.open macro Chuck W[_2_] Excel Programming 5 August 24th 07 04:58 PM
excel open in outlook if outlook is running kirk Excel Discussion (Misc queries) 0 May 24th 06 06:42 PM
Lookup an email address in Outlook based on Username (newbie quest HP Excel Programming 4 August 19th 05 04:18 PM
Using XL to grab current user's Outlook calendar item titles, dates, and durations? KR Excel Programming 2 November 22nd 04 06:25 PM


All times are GMT +1. The time now is 08:41 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"