Command button to open specific Excel document

M

Mike

I have a form that I would like to add a command button to and I would like
for this command button to open a specific file in Excel from my network. Is
this possible and how would I go about do this if so?
 
D

Dirk Goldgar

Mike said:
I have a form that I would like to add a command button to and I would like
for this command button to open a specific file in Excel from my network.
Is
this possible and how would I go about do this if so?


Probably the simplest way is to use the FollowHyperlink method, coding the
button's Click even procedure along these lines:

Private Sub cmdYourButtonName_Click()

Application.FollowHyperlink "\\Your\Network\Path\YourFile.xls"

End Sub
 
L

Lars Brownie

Mike,

My experience is, that followhyperlink is slower than using the explicit
Excel reference. Maybe worth while to check it out.

Dim appExcel As Excel.Application
Dim myWorkbook As Excel.Workbook
Set appExcel = CreateObject("Excel.Application")
Set myWorkbook = appExcel.Workbooks.Open("C:\YourFile.xls")
appExcel.Visible = True
Set appExcel = Nothing
Set myWorkbook = Nothing


Lars
 
D

Dirk Goldgar

Lars Brownie said:
Mike,

My experience is, that followhyperlink is slower than using the explicit
Excel reference. Maybe worth while to check it out.

Dim appExcel As Excel.Application
Dim myWorkbook As Excel.Workbook
Set appExcel = CreateObject("Excel.Application")
Set myWorkbook = appExcel.Workbooks.Open("C:\YourFile.xls")
appExcel.Visible = True
Set appExcel = Nothing
Set myWorkbook = Nothing


I've never compared the two approaches for speed, so you could be right. I
would recommend, though, that when taking that approach you use late binding
so as to avoid having to set a reference to the Excel object library:

Dim appExcel As Object
Dim myWorkbook As Object

That way, you run less risk of a broken reference if your distribute your
database to a different computer with a different version of Excel on it.
 
M

Mike

To Dirk and Lars, I thank you both on your efforts in helping me. I have to
say both options worked great but I went with last option given. Again
thanks for all your help and its guys like you that make the world go round!

Mike
 

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