VBA - How to open "excelfile.xls" from access CMD

M

MVP - WannaB

Hi, and thank you for all your help.
I've created a command button that opens EXCEL (that's simple) but how can I
modify the VBA as to exactly which file to open?

Here is the VBA that was created when I created the CMD button;
' USING XL 2003, SO I COMMENTED OUT THE XL 97 LINES
Private Sub CMD_SNL_Click()
On Error GoTo Err_CMD_SNL_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_CMD_SNL_Click:
Exit Sub

Err_CMD_SNL_Click:
MsgBox Err.Description
Resume Exit_CMD_SNL_Click

End Sub
 
D

Douglas J. Steele

Are you actually using Automation (i.e. controlling Excel from Access), or
do you just want the spreadsheet opened?

If the latter, just use Application.FollowHyperlink strPath (where strPath
contains the full path to the workbook you want opened)

It the former, add

oApp.Workbooks.Open strPath
 
D

Douglas J. Steele

Try:

Private Sub CMD_XL_Click()
On Error GoTo Err_CMD_XL_Click

Dim oApp As Object
Dim StrFile As String
Dim StrXLA As String


Set oApp = CreateObject("Excel.Application")
StrFile = "\\TservMod02\Tfln$\AProj\Linx\UpdateL_.XLT"
StrXLA = "...."
oApp.Visible = True
oApp.workbooks.Open StrFile
oApp.AddIns.Add strXLA, True

Exit_CMD_XL_Click:
Exit Sub

Err_CMD_XL_Click:
MsgBox Err.Description
Resume Exit_CMD_XL_Click

End Sub
 

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