Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening excel sheet from a button 1

Status
Not open for further replies.

tontenn

Vendor
Joined
Dec 29, 2006
Messages
54
Location
AU
Hi Guys

This may seem painfully easy but its cuasing me some grief. I created a button that opens a word document on my server automatically. Code below.

Private Sub Command1_Click()
Dim oApp As Object
Dim oDoc As Object
Set oApp = CreateObject("Word.Application")
oApp.Visible = True
Set oDoc = oApp.Documents.Open("\\Csc-server\Common\CSC\Contact Management\CSC CONTACT MANAGEMENT SYSTEM MANUAL - FINAL.doc")

End Sub

This works very well indeed. But what I am now trying to do is use a similar button to open an excel worksheet in the same folder on the server with the code below.

Private Sub Command2_Click()
Dim oApp As Object
Dim oDoc As Object
Set oApp = CreateObject("Excel.Application")
oApp.Visible = True
Set oDoc = oApp.Documents.Open("\\Csc-server\Common\CSC\Contact Management\CSCContactPhonebookContentsPage-RSversion.xls")

End Sub

Problem is it is coming back with a error message. "Run-time error 438, Object doesnt support this property or method" and highlights the path to the document.

Is there something I have missed or done that I need to do differently for an excel sheet as opposed to a word doc. The excel sheet opens up fine, just the document doesnt show.

Hope you can help.

Thanks in advance.

Tones
 
Hi Tontenn
I think your error is in the line
'Set oDoc = oApp.Documents.Open("\\Csc-server\Common\CSC\Contact Management\CSCContactPhonebookContentsPage-RSversion.xls")'
I believe it should be something like
oApp.workbooks.Open
I'm not sure if its workbooks, but documents is for opening word files. presentations for powerpoint, so I'm assuming workbooks for excel.


Crabback
 
Hey Crabback

Thanks for your quick response. Good thinking so I changed that to workbooks and still no luck.

This time came up with "Runtime Error 1004" and said the document could not be found.

So at this stage Im none the wiser. But thanks for your try.

Tones
 
Private Sub Command2_Click()
Dim oApp As Object
Set oApp = CreateObject("Excel.Application")
oApp.Visible = True
oApp.Workbooks.Open "\\Csc-server\Common\CSC\Contact Management\CSCContactPhonebookContentsPage-RSversion.xls"
Set oApp = Nothing
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top