Command Prompt Opening Excel

rahulbassi

Board Regular
Joined
Aug 14, 2011
Messages
130
Hello Team,

I'm opening excel file from command prompt using below command:

Code:
start excel.exe "D:\Temp\MyFile.xls" /e/%SR%-%CR%
SR and CR are two arguments being passed.

When Excel files open, I'm checking if it is being opened by command prompt or by user manually. This helps me decide if to expect arguments or not.

Code:
CmdRaw = GetCommandLine
    CmdLine = CmdToSTr(CmdRaw)
    
   If Right(CmdLine, 3) = "dde" Then
        'Not Opened from Batch File
        'Do Nothing
   Else
    'Opened from Batch File
    'Capture the SR and CR Numbers
End If
The problem is when opened by user manually. The file opens without Error if there is No other excel file already opened. It stays in IF block.

But, If there is some other excel file already opened and user tries to open this file, it goes into Else Part.

Can you please suggest.

Thanks,
Rahul
 

Some videos you may like

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Watch MrExcel Video

Forum statistics

Threads
1,102,448
Messages
5,486,958
Members
407,574
Latest member
Greso

This Week's Hot Topics

Top