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
 
M

MVP - WannaB

Not using automation, yet, but that may be in the future.
I just need to open the spreadsheet. The user opens a spreadsheet template
which allows them to retrieve data from an internet site, the spreadsheet is
then saved to another spreadsheet which is linked in the database. When the
user returns to the database (after saving and closing the excel file) they
click another button which updates that company's data from the linked
spreadsheet.
Thank you very much, for both of those options.
=============================
 
M

MVP - WannaB

This would work exactly as needed EXCEPT the spreadsheet needs to open a
linked XLA file which provides the functions used to retrieve the internet
data.
When I use oApp.WorkBooks.Open StrPath it opens the XL file but displays a
prompt that the workbook contains links to other data sources, with 3 options
"Update", "Don't Update", "Help" after clicking "Update" a promppts is
displayed explaining that the lnks can not be updated.
Is there something that can be done to ensure that EXCEL opens with the XLA
file as it normally does?
HERE IS THE VBA >>
Private Sub CMD_XL_Click()
On Error GoTo Err_CMD_XL_Click

Dim oApp As Object
Dim StrFile As String

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

Exit_CMD_XL_Click:
Exit Sub

Err_CMD_XL_Click:
MsgBox Err.Description
Resume Exit_CMD_XL_Click

End Sub
============================
 
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