Sorry, another no doubt silly question on VBA...

TartanSpecial

New Member
Joined
May 29, 2005
Messages
42
Continuing in a mini-series of TartanSpecial not having a clue about VBA.....

One of the reports I've inherited in my job has the code below. The code is actually in Business Object but open up a series of Excel files. The files open correctly but for some reason at the very end the file "Service_Comms_Ranking1" re-open , overwriting the changes already made.

Nothing in the Excel files seems to prompt it do so. I was wondering if anything in this code would prompt the file to be opened twice (or whether it lurks somewhere else)

As always any help is really gratefully received


Sub LaunchRankingExcel()
Const blank As String = " "
Dim retval
Dim filename, sWorkingDir, sOutputDir As String
Dim objXLS As New Excel.Application
Dim sCommandLine As String
Dim sXLInstallationDir As String

Application.Interactive = True

sWorkingDir = Application.GetInstallDirectory(boDocumentDirectory) & "\"
sOutputDir = "\\ldnroot\data\Equities\Trading\MDM\CMT_reporting\Marketing Packs\Embedded Charts DO NOT ERASE\"

Set objXLS = Excel.Application
objXLS.Visible = False
objXLS.Interactive = False
objXLS.DisplayAlerts = False

sXLInstallationDir = objXLS.Path & "\"
filename = "Service_Comms_Ranking1"

objXLS.Quit
Set objXLS = Nothing
If Application.Interactive Then
sCommandLine = sXLInstallationDir & "Excel.exe " & Chr$(34) & sOutputDir & filename & Chr$(34)
retval = Shell(sCommandLine, vbNormalFocus)
End If

End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi TartanSpecial,

It appears that the lines:

sCommandLine = sXLInstallationDir & "Excel.exe " & Chr$(34) & sOutputDir & filename & Chr$(34)
retval = Shell(sCommandLine, vbNormalFocus)

are intended to re-open Excel, this time opening workbook Service_Comms_Ranking1. It looks to me like the code opens Excel the first time without opening the workbook just to find out where it is installed, then closes it and re-opens using a Shell command--which opens it as a separate process--to open the workbook.

If your computer has Excel.exe properly registered and the search path set up properly, I don't believe opening it the first time to find the installation directory is required. I suggest you try just running the following code instead:

Code:
Sub LaunchRankingExcel()

Dim retval
Dim filename As String, sOutputDir As String
Dim sCommandLine As String

Application.Interactive = True

sOutputDir = "\\ldnroot\data\Equities\Trading\MDM\CMT_reporting\Marketing Packs\Embedded Charts DO NOT ERASE\"

filename = "Service_Comms_Ranking1"

If Application.Interactive Then
sCommandLine = "Excel.exe " & Chr$(34) & sOutputDir & filename & Chr$(34)
retval = Shell(sCommandLine, vbNormalFocus)
End If

End Sub

Please let me know if this works (or not).

Damon
 
Upvote 0
Thanks

Hi Damon

Thanks a lot for taking a look at this.

I ran the new code but got an error on the line -

retval = Shell(sCommandLine, vbNormalFocus)

Run Time Error 53 File not Found

Any ideas

Thanks for your looking into this
Nick
 
Upvote 0

Forum statistics

Threads
1,214,822
Messages
6,121,767
Members
449,049
Latest member
greyangel23

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