Command button to open specific Excel document

  • Thread starter Thread starter Mike
  • Start date Start date
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?
 
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
 
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
 
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.
 
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
 
Back
Top