retval = Shell("excel.exe """ & filename & """", vbNormalFocus)

condorelli

New Member
Joined
Jul 27, 2017
Messages
12
Hi all!
Is there any way to choose a sheet in
retval = Shell("excel.exe """ & filename & """", vbNormalFocus)
????
I need to open another excel file with "shell" in a specific sheet.

Thanks
 
What about if you replace the Debu.print line with the following :
Code:
Debug.Print GetObject(filename).FullName
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
If the line :
Code:
Debug.Print GetObject(filename).FullName
shows the correct file name but the line :
Code:
GetObject(filename).Sheets(strTestString).Select
generates error 1004, it means there is no sheet in the workbook with name held in the strTestString variable.
 
Upvote 0
If the line :
Code:
Debug.Print GetObject(filename).FullName
shows the correct file name but the line :
Code:
GetObject(filename).Sheets(strTestString).Select
generates error 1004, it means there is no sheet in the workbook with name held in the strTestString variable.

The code...
Code:
Private Sub Workbook_Open()

    Dim strTestString
    strTestString = Left(ThisWorkbook.Name, (InStrRev(ThisWorkbook.Name, ".", -1, vbTextCompare) - 1))

    Excel.Application.Workbooks.Open("\\xxx\yyy\fileB.xlsm").Sheets(strTestString).Activate
    ActiveWindow.WindowState = xlMaximized
    
    ThisWorkbook.Close SaveChanges = False

End Sub
...is actually working so the problem can't be strTestString variable

I need to open a new instance so i have to...
Code:
    retval = Shell("excel.exe """ & filename & """", vbNormalFocus)
...but I can't get it to work
 
Last edited:
Upvote 0
Instead of shelling the new application you could automate it using the New Keyword ... something like this :

Code:
Dim oXlApp As New Application

oXlApp.Workbooks.Open("\\xxx\yyy\fileB.xlsm").Sheets(strTestString).Activate

Edit

Use oXlApp.Visible=True before opening the workbook.
 
Last edited:
Upvote 0
Instead of shelling the new application you could automate it using the New Keyword ... something like this :

Code:
Dim oXlApp As New Application

oXlApp.Workbooks.Open("\\xxx\yyy\fileB.xlsm").Sheets(strTestString).Activate

Edit

Use oXlApp.Visible=True before opening the workbook.

FileB load up in the correct sheet
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,304
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top