473,606 Members | 2,218 Online
Bytes | Software Development & Data Engineering Community
+ 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(Cance l As Integer)
Dim file As String
Dim files As String
files = ""
file = Dir$("C:\My Document\Letter s\*.*")
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 9994
> ...
file = Dir$("C:\My Document\Letter s\*.*")
...
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.Fol lowHyperlink "C:\My Documents\Lette rs\" & 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\Letter s\*.*")
...
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.Fol lowHyperlink "C:\My Documents\Lette rs\" & Me!List1.Value

HTH - Peter

Nov 12 '05 #3
>> Application.Fol lowHyperlink "C:\My Documents\Lette rs\" & 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.dl l" Alias "ShellExecu teA" _
(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\Lette rs\" & 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.Fol lowHyperlink "C:\My Documents\Lette rs\" & 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.dl l" Alias "ShellExecu teA" _
(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\Lette rs\" & 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.Fol lowHyperlink "C:\My Documents\Lette rs\" & 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.dl l" Alias "ShellExecu teA" _
(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\Lette rs\" & 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(Cance l 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\Lette rs\" & 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\Lette rs\" & 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
14922
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) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
5
2819
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 invisible() { alert("invisible() called"); } }
2
7671
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 like mine to run immediately after it. So in the code below, what JS would i need to add to my "myfile.inc" page so that I could guarantee this behavior? <!-- main page --> <html> <head> <script type="text/javascript">
2
12677
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
5090
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 constructors (these three I knew about), but also conditional function definitions, as described in http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Defining_Functions ]. An example: function fun() {
3
3639
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' that takes arguments of type (void *) because the ADT must be able to deal with any type of data. In my actual code, I will code the function to take arguments of their real types, then when I pass this pointer through an interface function, I...
2
5312
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: 1>make_buildinfo.obj : error LNK2019: unresolved external symbol __imp__RegQueryValueExA@24 referenced in function _make_buildinfo2 Ask on python-list@python.org . - Josiah
28
4302
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
2112
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
3205
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 bastard so posting it before I forgot again... By taking this minimum code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head>
0
8015
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6770
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5966
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5465
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3930
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3977
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1553
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1296
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.