Open a specific Excel Workbook

S

Skip Bisconer

I would like to open a specific workbook with this code. Can someone tell
what I should insert. Everything I have tried doesn't work, possibly because
I don't know what I am doing.

Private Sub OpenExcel_Click()
On Error GoTo Err_OpenExcel_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_OpenExcel_Click:
Exit Sub

Err_OpenExcel_Click:
MsgBox Err.Description
Resume Exit_OpenExcel_Click

End Sub
 
O

Ofer Cohen

To open a specific excel file you can try using FollowHyperlink


Dim strFolderAndFile As String
strFolderAndFile = "C:\MyLocation\FileName.xls"
Application.FollowHyperlink strFolderAndFile
 
S

Skip Bisconer

Thanks for responding

I now have the following code and it gives me an Access error that it cannot
open the indicated file. It seemed to work correctly the first time I tried
it however it repeated the process on me and opened it again and since I put
it the transferspreadsheet command in it won't work.

Private Sub OpenExcel_Click()
On Error GoTo Err_OpenExcel_Click


Dim oApp As Object
Dim strFolderAndFile As String

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "Skip-Customer
Monitor By Quarters", _
"C:\Documents and Settings\Milo E Bisconer\My Documents\Ben's
Business\24MonthHistoryExported.xls"


Set oApp = CreateObject("Excel.Application")
oApp.Visible = True
oApp.UserControl = True

strFolderAndFile = _
"C:\Documents and Settings\Milo E Bisconer\My Documents \ Ben 's
Business\24MonthHistoryExported.xls"
Application.FollowHyperlink strFolderAndFile


Exit_OpenExcel_Click:
Exit Sub

Err_OpenExcel_Click:
MsgBox Err.Description
Resume Exit_OpenExcel_Click

End Sub
 
B

boblarson

As Ofer was telling you, try using HIS code WITHOUT the other stuff. You do
not need the CreateObject method with his followhyperlink code.

So, to write it out explicitly so there's no mistake:
Dim strFolderAndFile As String

strFolderAndFile = _
"C:\Documents and Settings\Milo E Bisconer\My Documents \ Ben 's
Business\24MonthHistoryExported.xls"

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "Skip-Customer
Monitor By Quarters", strFolderAndFile

Application.FollowHyperlink strFolderAndFile

--
Bob Larson
Access World Forums Super Moderator
Utter Access VIP
Tutorials at http://www.btabdevelopment.com
__________________________________
If my post was helpful to you, please rate the post.
 

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