-2

I have a file named USER_PREM_HOL_AMT.bat.

The code inside is:

set datename=%date% %username% %~n0   
:CheckOS   
IF EXIST "C:\Program Files\Microsoft Office\Office14\EXCEL.exe" (GOTO OFFICE2010) ELSE (GOTO OFFICE2013)

:OFFICE2010  
ECHO %datename%>>"O:\Holiday.log"  
START "" "C:\Program Files\Microsoft Office\Office14\EXCEL.exe" /e "file://///Log_files\Holiday.xlsm"
EXIT   
GOTO END   

This currently gives the log:

Tue 09/11/2018 7098703 USER_PREM_HOL_AMT

I want it to give me

Tue 09/11/2018 7098703 Holiday.xlsm 

Is there a way to do this? Get the file name it's opening instead of its own name.

Compo
  • 36,585
  • 5
  • 27
  • 39
  • i want it to log the name of the file it opens, not the batch-file's own name ..!! – Giridhar Venkateswaran Sep 11 '18 at 16:27
  • You can use `START "" "C:\Log_files\Holiday.xlsm"` and the command __START__ finds out automatically which application to use for opening the file with file extension `.xlsm`. How this works is explained at [Where is “START” searching for executables?](https://stackoverflow.com/a/27386403/3074564) It is also possible to force opening the *.xlsm file with Microsoft Excel using `START "" Excel.exe "C:\Log_files\Holiday.xlsm"` if Microsoft Excel is installed at all. – Mofi Sep 11 '18 at 17:40
  • Do you know that `/` is interpreted as ``\`` which is the directory separator and therefore both slashes cannot be used in a file name? See [Naming Files, Paths, and Namespaces](https://learn.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file) for learning the basics about Windows file systems. – Mofi Sep 11 '18 at 17:43

1 Answers1

1

You can change the first line to specify the filename.

set "datename=%date% %username% Holiday.xlsm"
lit
  • 14,456
  • 10
  • 65
  • 119