Need to set a VBA function to run "File Open" dialogue box

B

Brent E

Good afternoon,

I am needing VBA code to allow me to specificy a directory, then runthe
"Open" file dialogue box so a user is able to select a file to open. Any
suggestions? Thanks.

Cordailly,
 
N

Nick Hodge

Brent

In Excel this is

Dim sFileName as String
sFileName=Application.GetOpenFileName()
Workbooks.Open Filename:=sFileName

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
(e-mail address removed)
 
B

Brent E

Yes.
Excellent. Thanks. Actually I need this for Word instead of Excel. Will this
work in Word too? Also I just want this to open the dialogue box and stop, I
don't want to specify a file so a user can select from them. What do u
suggest?
 
N

Nick Hodge

Wow...an expedition into Word....

Sub openFile()
Application.Dialogs(wdDialogFileOpen).Show
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
(e-mail address removed)
 
K

Karl E. Peterson

Brent said:
Also I just want this to open the dialogue box and stop,
I don't want to specify a file so a user can select from them.

Are you just looking to obtain a filename from the user, not necessarily open the
file itself in Word? If so, I suspect you'd want to use the GetOpenFileName API
instead of the native object model methods in Word.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top