Open Word File using Dir Function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paolo

    Open Word File using 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.
  • Pieter Linden

    #2
    Re: Open Word File using Dir Function

    jprma@tin.it (Paolo) wrote in message news:<9f41a860. 0310190845.ebb9 8ba@posting.goo gle.com>...[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(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.[/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

    Comment

    • AccessDev

      #3
      Re: Open Word File using Dir Function

      jprma@tin.it (Paolo) wrote in message news:<9f41a860. 0310190845.ebb9 8ba@posting.goo gle.com>...[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(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.[/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

      Comment

      • Paolo

        #4
        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.n et (AccessDev) wrote in message news:<41c55781. 0310191800.297d 3af4@posting.go ogle.com>...[color=blue]
        > jprma@tin.it (Paolo) wrote in message news:<9f41a860. 0310190845.ebb9 8ba@posting.goo gle.com>...[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(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.[/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]

        Comment

        • Paolo

          #5
          Re: Open Word File using Dir Function

          Thanks Ted,

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

          Thanks.

          AccessDev@att.n et (AccessDev) wrote in message news:<41c55781. 0310191800.297d 3af4@posting.go ogle.com>...[color=blue]
          > jprma@tin.it (Paolo) wrote in message news:<9f41a860. 0310190845.ebb9 8ba@posting.goo gle.com>...[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(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.[/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]

          Comment

          • Pieter Linden

            #6
            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.Documen ts.Add(strFile) .



            see here:


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


            HTH,
            pieter

            Comment

            Working...