Input box to find file in WORD

vane0326

Well-known Member
Joined
Aug 29, 2004
Messages
819
I have this code But for some reason it does not work. It pops up a inputbox and I type the file name in the box and hit enter it suppose to find the file in word but does nothing,

Any Ideas?

Code:
Sub FindFile()

Dim GetFile()
Dim Filename As String
On Error Resume Next
Filename = InputBox("What File do you wish to open?")
Workbooks.Open ("C:\" & Filename & ".DOC")


End Sub
 
Hi Tom,

Just to let you know this code for Microsoft Publisher works now. But I can't figuer it out how to keep the code in the Visual Basic. I tried to do as a Add-in but it wont take it. It works only if I manually import the module in but thats not efficient, it would be nice to just open Microsoft Publisher and the code is there. If you have any ideas please let know.

Thanks! :-D


Code:
Sub Find_File()
Dim myFile$
myFile = InputBox _
("Enter the Publisher document file name:", _
"What File do you wish to open?", _
"YourFileName")
If myFile = "" Then Exit Sub
 
Dim myPath$, myDoc$
myPath = "C:\"
myDoc = myPath & myFile & ".Pub"
 
If Dir(myDoc) = "" Then
    MsgBox "The file ''" & myPub & "'' was not found.", 48, "No such animal."
    Exit Sub
End If
 
Application.Open myDoc
 
End Sub
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,224,845
Messages
6,181,298
Members
453,030
Latest member
PG626

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top