473,480 Members | 3,135 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Dir Function

Friends,

I have created a form with a list box that shows all my Word files.
I have then added the following code (found on comp.databases
newsgroup) to the Open event of my form and it works fine:

Private Sub Form_Open(Cancel As Integer)
Dim file As String
Dim files As String
files = ""
file = Dir$("C:\My Document\Letters\*.*")
While Len(file) > 0
files = files & file & ";"
file = Dir$
Wend
List1.RowSource = files
End Sub

What I would now like is to be able to open the selected file by
clicking on it from the listbox. Is this possible?

Thanks.
Nov 12 '05 #1
9 9984
> ...
file = Dir$("C:\My Document\Letters\*.*")
...
List1.RowSource = files
...
What I would now like is to be able to open the selected file by
clicking on it from the listbox. Is this possible?


Open in Word? Then this is the easiest method:

Application.FollowHyperlink "C:\My Documents\Letters\" & Me!List1.Value

HTH - Peter

--
No mails please.
Nov 12 '05 #2
Thanks, I have done a Paste of your code and added to the click event
of my list box but an error show up:
File name or class name not found during Automation operation (Error
432).

Any idea? Sorry I am not too clear but do not know much of VBA.

Thanks.

Peter Doering <no****@doering.org> wrote in message news:<bm************@ID-204768.news.uni-berlin.de>...
...
file = Dir$("C:\My Document\Letters\*.*")
...
List1.RowSource = files
...
What I would now like is to be able to open the selected file by
clicking on it from the listbox. Is this possible?


Open in Word? Then this is the easiest method:

Application.FollowHyperlink "C:\My Documents\Letters\" & Me!List1.Value

HTH - Peter

Nov 12 '05 #3
>> Application.FollowHyperlink "C:\My Documents\Letters\" & Me!List1.Value
Thanks, I have done a Paste of your code and added to the click event
of my list box but an error show up:
File name or class name not found during Automation operation (Error
432).


Well, it works for me.

Another method (by Jonathan West, found in qoogle). As I don't get your
error I don't know whether it will cure the problem on your side, just give
it a try:

1. Copy this code to a new module.

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

Public Function HyperJump(ByVal URL As String) As Long
HyperJump = ShellExecute(0&, vbNullString, URL, vbNullString, _
vbNullString, vbNormalFocus)
End Function

2. Copy this code to your listbox procedure:

HyperJump "C:\My Documents\Letters\" & Me!List1.Value
HTH - Peter

--
No mails please.
Nov 12 '05 #4
Thanks Peter it works great.

Peter Doering <no****@doering.org> wrote in message news:<bn************@ID-204768.news.uni-berlin.de>...
Application.FollowHyperlink "C:\My Documents\Letters\" & Me!List1.Value

Thanks, I have done a Paste of your code and added to the click event
of my list box but an error show up:
File name or class name not found during Automation operation (Error
432).


Well, it works for me.

Another method (by Jonathan West, found in qoogle). As I don't get your
error I don't know whether it will cure the problem on your side, just give
it a try:

1. Copy this code to a new module.

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

Public Function HyperJump(ByVal URL As String) As Long
HyperJump = ShellExecute(0&, vbNullString, URL, vbNullString, _
vbNullString, vbNormalFocus)
End Function

2. Copy this code to your listbox procedure:

HyperJump "C:\My Documents\Letters\" & Me!List1.Value
HTH - Peter

Nov 12 '05 #5
Thanks, your code works fine. Just one more thing.
The list box I have created display the file names and extensions (ex.
Letter.doc). I would like not to diplay the extension and just see the
file name. Is there a way? Thanks.
Peter Doering <no****@doering.org> wrote in message news:<bn************@ID-204768.news.uni-berlin.de>...
Application.FollowHyperlink "C:\My Documents\Letters\" & Me!List1.Value

Thanks, I have done a Paste of your code and added to the click event
of my list box but an error show up:
File name or class name not found during Automation operation (Error
432).


Well, it works for me.

Another method (by Jonathan West, found in qoogle). As I don't get your
error I don't know whether it will cure the problem on your side, just give
it a try:

1. Copy this code to a new module.

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

Public Function HyperJump(ByVal URL As String) As Long
HyperJump = ShellExecute(0&, vbNullString, URL, vbNullString, _
vbNullString, vbNormalFocus)
End Function

2. Copy this code to your listbox procedure:

HyperJump "C:\My Documents\Letters\" & Me!List1.Value
HTH - Peter

Nov 12 '05 #6
> The list box I have created display the file names and extensions (ex.
Letter.doc). I would like not to diplay the extension and just see the
file name. Is there a way? Thanks.


Simple way:

files = files & Left(file, Len(file)-4) & ";"

This is hardcoded for 3 char's extension, i.e. not very clean. When you
open the document you have to add ".doc" again.

Peter

--
No mails please.
Nov 12 '05 #7
Thanks for your patiente Peter, but I have changed the code as
follows:
Private Sub Form_Open(Cancel As Integer)
Dim file As String
Dim files As String

files = ""
file = Dir$("\\S0A3AA0\Shared\FBU Tools\Test Forms\*.dot")
While Len(file) > 0
files = files & Left(file, Len(file) - 4) & ";"
file = Dir$
Wend
List1.RowSource = files
End Sub

I now see just the files names but am not able to open them.

Any idea? and what about the .doc ext you where talking about. Where
do I type that? Thanks.
Peter Doering <no****@doering.org> wrote in message news:<bn************@ID-204768.news.uni-berlin.de>...
The list box I have created display the file names and extensions (ex.
Letter.doc). I would like not to diplay the extension and just see the
file name. Is there a way? Thanks.


Simple way:

files = files & Left(file, Len(file)-4) & ";"

This is hardcoded for 3 char's extension, i.e. not very clean. When you
open the document you have to add ".doc" again.

Peter

Nov 12 '05 #8
> ...
file = Dir$("\\S0A3AA0\Shared\FBU Tools\Test Forms\*.dot")
...
I now see just the files names but am not able to open them.
This is the reason why I wrote ...
... When you open the document you have to add ".doc" again.


You are looking for *.dot (= document templates), not *.doc (= document
files) as in my example. You have to add this extension (*.dot) to the open
statement, because you don't have it in Me!List1.Value anymore:

HyperJump "C:\My Documents\Letters\" & Me!List1.Value & ".dot"

HTH - Peter

--
No mails please.
Nov 12 '05 #9
Thanks. Works great.

Peter Doering <no****@doering.org> wrote in message news:<bn************@ID-204768.news.uni-berlin.de>...
...
file = Dir$("\\S0A3AA0\Shared\FBU Tools\Test Forms\*.dot")
...
I now see just the files names but am not able to open them.


This is the reason why I wrote ...
... When you open the document you have to add ".doc" again.


You are looking for *.dot (= document templates), not *.doc (= document
files) as in my example. You have to add this extension (*.dot) to the open
statement, because you don't have it in Me!List1.Value anymore:

HyperJump "C:\My Documents\Letters\" & Me!List1.Value & ".dot"

HTH - Peter

Nov 12 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
14898
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
5
2805
by: phil_gg04 | last post by:
Dear Javascript Experts, Opera seems to have different ideas about the visibility of Javascript functions than other browsers. For example, if I have this code: if (1==2) { function...
2
7658
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
2
12660
by: sushil | last post by:
+1 #include<stdio.h> +2 #include <stdlib.h> +3 typedef struct +4 { +5 unsigned int PID; +6 unsigned int CID; +7 } T_ID; +8 +9 typedef unsigned int (*T_HANDLER)(void); +10
8
5073
by: Olov Johansson | last post by:
I just found out that JavaScript 1.5 (I tested this with Firefox 1.0.7 and Konqueror 3.5) has support not only for standard function definitions, function expressions (lambdas) and Function...
3
3621
by: Beta What | last post by:
Hello, I have a question about casting a function pointer. Say I want to make a generic module (say some ADT implementation) that requires a function pointer from the 'actual/other modules'...
2
5298
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
28
4268
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
4
2099
by: alex | last post by:
I am so confused with these three concept,who can explained it?thanks so much? e.g. var f= new Function("x", "y", "return x * y"); function f(x,y){ return x*y } var f=function(x,y){
7
3178
by: VK | last post by:
I was getting this effect N times but each time I was in rush to just make it work, and later I coudn't recall anymore what was the original state I was working around. This time I nailed the...
0
7055
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6920
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7110
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5367
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4503
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3015
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3011
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
574
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
210
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.