open file

J

Joel Allen

Hello,

I have code in my custom task form that opens a file:


Sub CommandButtonQuoteBasedOnGo_Click()

Dim objWeb
On Error Resume Next
Set objWeb = CreateObject("InternetExplorer.Application")
objWeb.Navigate Item.UserProperties("QuoteBasedOn").value
objWeb.Visible = True

End Sub


Is there a way to just open the file without IE? - in a way that would be
the same as double cliking the file in Windows Explorer.

Thank you very much,
Joel
 
G

Guest

You cannot open files with VBScript. You'd need to use VBA/VB or call a
custom dll within your script that implements shell functionality. A
typical command to open files uses the following Win32 API declaration:

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

--
Eric Legault [MVP - Outlook]
MCDBA, MCTS (Messaging & Collaboration, SharePoint Infrastructure, MOSS 2007
& WSS 3.0 Application Development)
Collaborative Innovations
-> Try Picture Attachments Wizard For Microsoft Outlook <-
Web: http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault
 
J

Joel Allen

THANK YOU!!! It worked.

Can I ask you one last question? I want to copy to the clipboard, and I
think this Shell usage would apply as well?

Set Myshell = CopyToClipboard?("WScript.Shell")
Myshell.Run "text text text"


Shell can be used in VBScript, too:

Set Myshell = CreateObject("WScript.Shell")
Myshell.Run "somefile.doc"

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
J

Joel Allen

The open Shell command works great for a simple string like this:

Set Myshell = CreateObject("WScript.Shell")
Myshell.Run "C:\normal.doc"

but as soon as the path is a lot longer like this:

Set Myshell = CreateObject("WScript.Shell")
Myshell.Run "C:\test\documents\misc\normal.doc"

I get an unknown exception error. How come?

Can you please help me again? Thank you!

Joel


No, VBScript doesn't provide clipboard access.
 
S

Sue Mosher [MVP-Outlook]

I have no idea why that would happen, unless there's an error in the path.
 
J

Joel

Ah ha, I found out that if there is a space in the path, it doesn't work.

This works:

Set Myshell = CreateObject("WScript.Shell")
Myshell.Run "C:\test.txt"

This doesn't work:

Set Myshell = CreateObject("WScript.Shell")
Myshell.Run "C:\test file.txt"

So how can I avoid this?

Thanks for all your help,
Joel
 
S

Sue Mosher [MVP-Outlook]

Try enclosing the path string with single quotes. That works for some other scenarios:

Myshell.Run "'C:\test file.txt'"

If that doesn't work, you might want to ask on a general WIndows programming forum. We're pretty far afield from Outlook code issues.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 

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

Similar Threads

navigate 1
Print from IE 3
URL's in Custom Forms 1
Link in label tag work working 3
Hyperlink in Outlook form v2 5
Label click not working 6
SueHelpMe 1
Open an Excel file located in a web page - How to open it 0

Top