Tech Support Guy banner
  • Please post in our Community Feedback thread for help with the new forum software! If you are having trouble logging in, please Contact Us for assistance.
Status
Not open for further replies.
1 - 12 of 12 Posts

·
Registered
Joined
·
4 Posts
Discussion Starter · #1 ·
Hi guys;

I'm working on my final year project and I need your help. I'm trying to open a word document from a VB application. I'm using a fileListBox. I want the file to open in Word when dblClicked. How can it be done?
 

·
Registered
Joined
·
106 Posts
Hi,

Shame, you can do good stuff in .net :-(

Shell works, though, as mosaic says.

Shell "c:\windows\notepad.exe c:\xxx.txt"

will fire up notepad with c:\xxx.txt loaded into it

Shell "c:\windows\notepad.exe c:\xxx.txt", vbMaximizedFocus

notepad maximised and with focus

Shell "c:\windows\notepad.exe c:\xxx.txt /c", vbMaximizedFocus

Note the /c which means that your calling program returns immediately and doesn't wait for notepad to be closed (this is almost undocumented and drove me up the wall many years ago!)

or you can get the task handle with:

x = Shell("c:\windows\notepad.exe c:\xxx.txt /c", vbMaximizedFocus)

and use SendKeys to control the program

HTH

Ian
 

·
Registered
Joined
·
7,486 Posts
And another problem with Shell is the Quotation marks. They can give you fits.
I take it you don't have anything in the click event.

If you actually are opening a Word Document and doc is associated with Word, And Word is installed on the System, (if others are going to use it) then I prefer the API call on this one.

ShellExecute

This will open the file in the app it is associated with.
 

·
Registered
Joined
·
3,015 Posts
Gazornenplat said:
Note the /c which means that your calling program returns immediately and doesn't wait for notepad to be closed (this is almost undocumented and drove me up the wall many years ago!)
The default behavior of Shell in VB6 is to return to the caller without waiting for the Shell'ed program to close.
 

·
Registered
Joined
·
4,916 Posts
Shell will only open the document. If you use early binding and set a reference to the Word Library, you can create an Instance of Word to open the document and completely control it. By using early binding, you will be able to use Intellisense to access the documents properties and methods.

Rollin
 

·
Registered
Joined
·
4 Posts
Discussion Starter · #11 ·
Hi Rollin;
Wouldn't setting a reference to the Word Library affect the portability of the application?
This seems to be a long process knowing that I want to open different file types, which means that I'll have to do the same with every file type I want my application to open.

Anas
 

·
Registered
Joined
·
4,916 Posts
Yes, there may be some portability issues with setting references to specific libraries. You can always use late binding without setting reference to any libraries.

Code:
Dim objXL As Object
Set objXL = CreateObject("Excel.Application")
objXL.Visible = True
objXL.Workbooks.Open ("C:\YourWorkbookName.xls")
' Add more code
Code:
Dim objWord As Object
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
objWord.Documents.Open ("C:\YourDocumentName.doc")
'Add more code
Rollin
 
1 - 12 of 12 Posts
Status
Not open for further replies.
Top