Word AddIn that opens an existing word document
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Word AddIn that opens an existing word document

Hybrid View

  1. #1
    Join Date
    Nov 2011
    Posts
    38

    Word AddIn that opens an existing word document

    I wrote a small Word AddIn program in VB that opens an existing Word document from a specified directory when you click on a button. Here is what I have so far...

    Dim Name As String
    Name = InputBox("Enter File Name: ")
    Console.WriteLine(Name)

    Dim objWord As Word.Application
    objWord = New Word.Application

    objWord.Visible = True
    objWord.Documents.Open("H:\SNH\" + Name, , , True)

    It works perfectly...However, I want to add an If statement, that outputs a message box saying File not found! when the file input is not found. Any help on how to add this new task?

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,984

    Re: Word AddIn that opens an existing word document

    how about DIR "H:\SNH\" + Name (best to use two statements)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Nov 2011
    Posts
    38

    Re: Word AddIn that opens an existing word document

    I mean something like...

    If ("H:\SNH\" contains (fileName))
    objWord.Documents.Open(fileName)
    Else
    MsgBox("File Not Found!")



    How can I make that work?

  4. #4
    Join Date
    Jul 2005
    Posts
    1,074

    Re: Word AddIn that opens an existing word document

    Do as David says:
    Code:
    If Dir("H:\SNH\" & Name, vbArchive) Then
        objWord.Documents.Open("H:\SNH\" + Name, , , True)
    Else
        MsgBox "File Not Found"
    End If
    JG


    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center