Want to open a file in a form

  • Thread starter Thread starter ladivapr
  • Start date Start date
L

ladivapr

Help me out guys. I have a form and I want a command button in the for
that opens a specific excel file. How do I do that? The most I can d
is open excel but not opening the specific file I want. Please guy
tell me how do I that. I will appreciate so much!!

div
 
The best way is to use code and the simplest is the Applicatio
FollowHyperlink method. In the OnClick event of a button put th
following code...


Code
-------------------

Application.FollowHyperlink "C:\Documents and Settings\Template.xls", , True, True

-------------------



changing the path and file name to whatever you want to open.

HT
 
Okay I tried doing a command button -run application excel and on th
onclick i wrote the code and it doesnt work :( I think Im putting i
the wrong place the code, not sure where do I put it, i mean dont kno
which command button I can do to do thi
 
Ok, I see what you have done wrong. In design view right click on th
button you created and select properties. Scroll down to OnClick an
then click the "..." button to the right of Event Procedure. This i
roughly what your code looks like at the moment...

Code
-------------------

Private Sub Command1_Click()
On Error GoTo Err_Command1_Click

Dim oApp As Object

Set oApp = CreateObject("Excel.Application")
oApp.Visible = True
'Only XL 97 supports UserControl Property
On Error Resume Next
oApp.UserControl = True

Exit_Command1_Click:
Exit Sub

Err_Command1_Click:
MsgBox Err.Description
Resume Exit_Command1_Click

End Sub

-------------------

you need to delete the middle part and add the code I sent. Your cod
should look like...

Code
-------------------

Private Sub Command1_Click()
On Error GoTo Err_Command1_Click

Application.FollowHyperlink "C:\Documents and Settings\Template.xls", , True, True

Exit_Command1_Click:
Exit Sub

Err_Command1_Click:
MsgBox Err.Description
Resume Exit_Command1_Click

End Sub
 
Back
Top