Command-line switches

  • Thread starter Thread starter TJ Dowling
  • Start date Start date
T

TJ Dowling

I'm trying to call an Excel file from Access VBA using the Shell command. I
want to be able to select one of two worksheets to be activated whenever I
make the call. One shows a monthly chart and the other a quarterly chart.

Is there a command-line switch that I can use when calling Excel.exe that
will activate the worksheet of my choice?

Thanks,
TJ Dowling
 
There are no commandline switches that will do this.

In fact, if you're using the Shell command, I'm not sure you can do it at all.

But you could use something like this instead:

Option Explicit
Sub testme()

Dim XLApp As Object
Dim XLWkbk As Object
Dim wkbkName As String
Dim XLWasRunning As Boolean

wkbkName = "C:\my documents\excel\book1.xls"

XLWasRunning = True
On Error Resume Next
Set XLApp = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Set XLApp = CreateObject("Excel.Application")
XLWasRunning = False
End If

XLApp.Visible = True 'at least for testing!

Set XLWkbk = XLApp.workbooks.Open(FileName:=wkbkName)

'this line will change depening on the sheet to select
XLApp.GoTo XLWkbk.worksheets("Sheet2").Range("a1")

Set XLWkbk = Nothing
Set XLApp = Nothing

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

Back
Top