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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Launch Excel from Access Module

Status
Not open for further replies.

Preston5

Programmer
Aug 31, 2001
4
US
I've read what has been archived about this topic and am trying this line of code:

Call Shell("C:\Win32App\MSOffice\Office\EXCEL.EXE" & Chr(34) & "c:\DeleteMe\" & strComboClient & "_Chart.xls")

The "strComboClient" is a variable passed from a combo box that builds a name for each spreadsheet. I can build the filename--I just can't seem to launch Excel and open the worksheet file.

Here's the error that I keep getting: "5 Invalid procedure call or argument."
 
You'd probably be better off using automation. That way, you could manipulate the objects in Excel and pass data and commands back and forth between Access and Excel.

The following looks up a corresponding file name in a table and loads an excel document.

Code:
Private Sub cmdCalDatasheet_Click()
'This sub displays an excel document based on variables in the form
'Dim objects and variables
Dim dbs
Dim RST
Dim strSQL
Dim objExcel As Object
Dim File
File = Me.txtCal_DSHT
Set dbs = CurrentDb
'Check for empty string or zeros
If File <> &quot;0&quot; And Not File Then ' No Zeros and not null
'Look up file name value in tblDocument
strSQL = &quot;SELECT tblDocument2.FileID, tblDocument2.File FROM tblDocument2 WHERE (((tblDocument2.FileID)=&quot; & File & &quot;))&quot;
Set RST = dbs.OpenRecordset(strSQL)
'Grab the Document name
File = RST.Fields(&quot;File&quot;).Value
'Launch word
Set objExcel = New Excel.Application
With objExcel
    'Open the file
    .Workbooks.Open FileName:=File
    'Make it visible
    .Visible = True
End With
'Maximize the window
objExcel.Application.WindowState = xlMaximized
Else
'Nothing there, display a message box
MsgBox &quot;There is no current Calibration Datasheet on file &quot;, vbOKOnly
End If
Set RST = Nothing
Set objExcel = Nothing
Set dbs = Nothing
'End Sub
End Sub
Tyrone Lumley
augerinn@gte.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top