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?
Re: Word AddIn that opens an existing word document
how about DIR "H:\SNH\" + Name (best to use two statements)
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?
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