Link to home
Start Free TrialLog in
Avatar of pmpatane
pmpataneFlag for United States of America

asked on

Outlook 2010 opening network url via vba

In Outlook 2010 I have code that needs to open a link.
Sub LinkFollow()

x = Shell("C:\Windows\explorer.exe  \\ntwkdata1\vol1\oft.url", vbMaximizedFocus)

End Sub

Open in new window

When I run the code, I get the window in the attached jpg.  How can I make that just automatically select Open?
User generated image
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

You can't Internet Explorer security will stop you.
Hi, pmpatane.

Please try this approach.  It works when the .url file is on a local drive.  I'm not in a position at the moment to test it on a network drive.

Private Declare Function ShellExecute Lib "shell32.dll" _
  Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
  ByVal lpFile As String, ByVal lpParameters As String, _
  ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

ShellExecute 0&, "open", "\\ntwkdata1\vol1\oft.url", 0&, 0&, 0&

Open in new window

Avatar of pmpatane

ASKER

Hi BlueDevilFan,
It appears David Johnston is correct, that it will be blocked.  The code you gave me produces the same result, that lovely dialog box.  Alas, my users will need to click the open button.
I've just tested this on my system and it worked perfectly opening a .url shortcut.  I tired it with IE and Firefox and both worked.  I don't know what you have your shortcut pointing to, I pointed mine to google.com, so perhaps that's the difference.
a hyperlink to a web address will never give you an open or save dialog it will always open. BlueDevilFan what made you think any differntly.  You are comparing apples to oranges as we are referring to a different mime type. a file that the browser doesn't know how to handle i.e. a word document then you are given the option to open or save the file. the file gets saved to disk in both cases but in different locations. with open the file exists in the browsers temporary folder and in the save option it is saved where the user wants it to be saved.
David - Good points.

pmpatane - What is you ultimate goal here?  If we knew that, then we might be able to suggest an alternative.
We have a macro running in Outlook, and at times it needs to open a template (.oft)  The template is stored in a location that most of our users do not have mapped, so the macro points to a shortcut on a shared drive.  But I just tested the code again putting in the exact internal URL and still I get that dialog box
ASKER CERTIFIED SOLUTION
Avatar of David Lee
David Lee
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That worked perfectly...THANKS!!
You're welcome!