Hi,
I am posting how I dealt with the issue in case it may help someone. Not the perfect solution but it works for me at the moment.
1. Create Macros in Outlook
Sub Location1()
'- change SMTP to desired Location1
Dim AltKey As String
Dim CtrlKey As String
Dim ShiftKey As String
Dim TabKey As String
Dim EnterKey As String
'--------------------------
AltKey = "%"
CtrlKey = "^"
ShiftKey = "+"
TabKey = "{TAB}"
EnterKey = "~"
SendKeys AltKey & "(TA)", False
SendKeys EnterKey, False
SendKeys AltKey & "(C)", False
SendKeys TabKey, False
SendKeys TabKey, False
SendKeys TabKey, False
SendKeys "SMTP FOR Location1", False
SendKeys AltKey & "(N)", False
SendKeys EnterKey, False
End Sub
2. Create Macros for each location required
3. Digitally sign the codes (you can use Selfcert.exe to get your certificate)
4. Create VBScript "outlook.vbs"
IP_Address = GetIP()
arrOctets = Split(IP_Address, ".")
Select Case arrOctets(0) & "." & arrOctets(1) & "." & arrOctets(2)
Case "111.222.3" 'Location = home
strMacro = "Location1"
Case "10.100.110" 'Location = office
strMacro = "Location2"
End Select
Set objShell = CreateObject("Wscript.Shell")
objShell.run "Outlook /autorun " & strMacro
Function GetIP()
Dim ws : Set ws = CreateObject("WScript.Shell")
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim TmpFile : TmpFile = fso.GetSpecialFolder(2) & "/ip.txt"
Dim ThisLine, IP
If ws.Environment("SYSTEM")("OS") = "" Then
ws.run "winipcfg /batch " & TmpFile, 0, True
Else
ws.run "%comspec% /c ipconfig > " & TmpFile, 0, True
End If
With fso.GetFile(TmpFile).OpenAsTextStream
Do While NOT .AtEndOfStream
ThisLine = .ReadLine
If InStr(ThisLine, "Address") <> 0 Then IP = Mid(ThisLine, InStr(ThisLine, ":") + 2)
Loop
.Close
End With
'WinXP (NT? 2K?) leaves a carriage return at the end of line
If IP <> "" Then
If Asc(Right(IP, 1)) = 13 Then IP = Left(IP, Len(IP) - 1)
End If
GetIP = IP
fso.GetFile(TmpFile).Delete
Set fso = Nothing
Set ws = Nothing
End Function
The code could be cleaned up but I cut and pasted from many sources (thanks all over the Web) and stopped when it worked. When you run the .vbs it checks the IP to identify your location and starts outlook plus the proper macro.
If you need to key on just the first two octets of the IP address, then replace this
Select Case arrOctets(0) & "." & arrOctets(1) & "." & arrOctets(2)
with
Select Case arrOctets(0) & "." & arrOctets(1)
The GetIP() function works but it will cause a problem if a wired and wireless NIC both have IP addresses at the same time. Also, SendKey may give trouble.
Again, thanks to all that helped me.