Connecting Tech Pros Worldwide Forums | Help | Site Map

Open Word File using Dir Function

Paolo
Guest
 
Posts: n/a
#1: Nov 12 '05
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.

Pieter Linden
Guest
 
Posts: n/a
#2: Nov 12 '05

re: Open Word File using Dir Function


jprma@tin.it (Paolo) wrote in message news:<9f41a860.0310190845.ebb98ba@posting.google.c om>...[color=blue]
> 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.[/color]

you could put code to automate Word in your double-click event of the
listbox and pass in the itemselected collection... of course, you
could probably also just use the OpenFile API at www.mvps.org/access
AccessDev
Guest
 
Posts: n/a
#3: Nov 12 '05

re: Open Word File using Dir Function


jprma@tin.it (Paolo) wrote in message news:<9f41a860.0310190845.ebb98ba@posting.google.c om>...[color=blue]
> 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.[/color]


Simply add the code to the OnClick event property of the list box so
that it will open MS Word and the specified document. Do you have that
code?
Ted
Paolo
Guest
 
Posts: n/a
#4: Nov 12 '05

re: Open Word File using Dir Function


Thanks Ted,

No I do not have that code and would really appreciate your help.

Thanks.

AccessDev@att.net (AccessDev) wrote in message news:<41c55781.0310191800.297d3af4@posting.google. com>...[color=blue]
> jprma@tin.it (Paolo) wrote in message news:<9f41a860.0310190845.ebb98ba@posting.google.c om>...[color=green]
> > 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.[/color]
>
>
> Simply add the code to the OnClick event property of the list box so
> that it will open MS Word and the specified document. Do you have that
> code?
> Ted[/color]
Paolo
Guest
 
Posts: n/a
#5: Nov 12 '05

re: Open Word File using Dir Function


Thanks Ted,

No I do not have that code and would appreciate you help.

Thanks.

AccessDev@att.net (AccessDev) wrote in message news:<41c55781.0310191800.297d3af4@posting.google. com>...[color=blue]
> jprma@tin.it (Paolo) wrote in message news:<9f41a860.0310190845.ebb98ba@posting.google.c om>...[color=green]
> > 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.[/color]
>
>
> Simply add the code to the OnClick event property of the list box so
> that it will open MS Word and the specified document. Do you have that
> code?
> Ted[/color]
Pieter Linden
Guest
 
Posts: n/a
#6: Nov 12 '05

re: Open Word File using Dir Function


You'll probably want the fIsAppRunning() function, and then if Word is
running, just activate it and then use AppWord.Documents.Add(strFile).

http://www.mvps.org/access/api/api0007.htm

see here:
http://www.mvps.org/access/modules/mdl0006.htm

for an example of using the function... (He's using Excel, but the
differences are really minor.)


HTH,
pieter
Closed Thread