Elp in opening file in vb.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Aravind Renjan
    New Member
    • Feb 2012
    • 7

    Elp in opening file in vb.

    i want to open a word doc in vb. i have opened it by giving the file name directly,but i want the file name to be given as per the selected name in a listbox and typed character in a textbox. i have typed the following code,

    Code:
    Private Sub Command1_Click()
    Dim objWord As Word.Application
    Set objWord = New Word.Application
    objWord.Visible = True
    objWord.Documents.Open App.Path & "List1.text" & "Text1.txt.docx"
    End Sub
    but it is not working as the valuers are not coming please help!!
    Last edited by Rabbit; Feb 21 '12, 04:30 PM. Reason: Please use code tags when posting code
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    App.Path & "List1.text " & "Text1.txt.docx "
    You must respect the commandline syntax to open a file.
    Like:
    If the Doc is in the path=

    "C:\myprogram\F older1\mydocume nt.docx"

    if List1.text = "Folder1" and Text1.txt = "mydocument " then the code is=

    Code:
    objWord.Documents.Open App.Path & "\" & List1.text & "\" & Text1.txt & ".docx"
    Last edited by Stewart Ross; Feb 20 '12, 06:21 PM. Reason: Added missing ampersand before Text1.txt in last code fragment

    Comment

    • Aravind Renjan
      New Member
      • Feb 2012
      • 7

      #3
      Thank you for your reply!
      But still the file is not opening. The value selected in list is not coming.that is 'folder1' is not coming in the path to be opened.
      please reply as soon as possible.

      Comment

      • Guido Geurs
        Recognized Expert Contributor
        • Oct 2009
        • 767

        #4
        Can you give an example of the contents of the list and the other items?
        Be cautious by the use of "App.Path" !!
        Is the file to open in the folder or sub folder of the .VBP and other files ?
        During the TEST RUN of the project the "App.path" is the folder where the .VBP and other files of the project are !!
        During the run of the compiled .EXE it's the folder where the PROGRAM is !!
        So the .DOC must always be in the folder (or sub folders) of the PROJECT or PROGRAM !!!

        Comment

        • Aravind Renjan
          New Member
          • Feb 2012
          • 7

          #5
          Ok. But the file opens if I put it out of the folder. But when in the folder then a box comes"F:/mydocument.docx "not found. So it is that the selected item name of list box is not coming in the path specified.
          Please reply fast!

          Comment

          • Guido Geurs
            Recognized Expert Contributor
            • Oct 2009
            • 767

            #6
            Do you know how to use "Break point" and "Add Watch" ?

            Comment

            Working...