There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
bios black screen blue screen boot computer connection crash css dell display driver drivers email error excel explorer firefox firefox 3 freeze game hard drive internet internet explorer itunes laptop linux malware monitor network networking nvidia outlook outlook 2003 outlook express partition password printer problem ram router slow sound startup trojan usb virus vista windows windows xp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
(VB) Open file by double clicking in the fileListBox


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
Anas's Avatar
Junior Member with 4 posts.
 
Join Date: Jan 2005
Experience: Intermediate
19-Jan-2005, 11:54 AM #1
(VB) Open file by double clicking in the fileListBox
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?
Mosaic1's Avatar
Distinguished Member with 7,502 posts.
 
Join Date: Aug 2001
19-Jan-2005, 02:58 PM #2
Use Shell to specify which program to use to open the file.
Gazornenplat's Avatar
Senior Member with 106 posts.
 
Join Date: Dec 2004
Location: Xabia, Spain
Experience: 20 years of programming
19-Jan-2005, 03:15 PM #3
What version of VB?

Ian
Anas's Avatar
Junior Member with 4 posts.
 
Join Date: Jan 2005
Experience: Intermediate
19-Jan-2005, 03:19 PM #4
Hi Ian;
I'm using VB 6.0
Gazornenplat's Avatar
Senior Member with 106 posts.
 
Join Date: Dec 2004
Location: Xabia, Spain
Experience: 20 years of programming
19-Jan-2005, 04:32 PM #5
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
Mosaic1's Avatar
Distinguished Member with 7,502 posts.
 
Join Date: Aug 2001
19-Jan-2005, 06:34 PM #6
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.
coderitr's Avatar
Distinguished Member with 3,080 posts.
 
Join Date: Oct 2003
20-Jan-2005, 09:10 PM #7
Quote:
Originally Posted by Gazornenplat
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.
Gazornenplat's Avatar
Senior Member with 106 posts.
 
Join Date: Dec 2004
Location: Xabia, Spain
Experience: 20 years of programming
20-Jan-2005, 09:24 PM #8
Ok, so it must have been the other way around. It had been a long day, and it was a long time ago :-)
Anas's Avatar
Junior Member with 4 posts.
 
Join Date: Jan 2005
Experience: Intermediate
20-Jan-2005, 09:35 PM #9
Thank you all guys;
The solution that Mosaic1 suggested seems to be what I'm looking for. I'll try it.
Rollin_Again's Avatar
Distinguished Member with 2,872 posts.
 
Join Date: Sep 2003
Location: Atlanta, GA - Planet Earth
Experience: Brilliant When Sober
22-Jan-2005, 01:42 AM #10
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
Anas's Avatar
Junior Member with 4 posts.
 
Join Date: Jan 2005
Experience: Intermediate
22-Jan-2005, 04:45 PM #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
Rollin_Again's Avatar
Distinguished Member with 2,872 posts.
 
Join Date: Sep 2003
Location: Atlanta, GA - Planet Earth
Experience: Brilliant When Sober
22-Jan-2005, 10:16 PM #12
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

Last edited by Rollin_Again : 22-Jan-2005 10:23 PM.
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 01:23 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.