I am a programmer although I have little to no experience with scripts and batch files.
Using this page as reference, it basically describes what I want to do: search for a file and return the path. Find file and return full path using a batch file
As soon as echo %p% is executed (so that I can see the value that was stored), all that is printed on the screen is "ECHO is off." From what I've read, this is either caused by spaces or because the value is blank.
From what I can tell, everything seems to be working fine.
I am trying to improve a current batch file by making it dynamic to handle path issues for 32 vs 64 bit programs and various Microsoft office versions.
This structure works:
IF EXIST "\\server\folder\file.dbf" (
"C:\Program Files (x86)\Microsoft Office\Office12\winword.exe" "\\server\folder\file.docx" /mDoMailMergeViewAllCG
)
Microsoft word is opened, the proper document is loaded then the macro is executed.
The following doesn't work:
@echo off
set PF=
set p=
rem Determine if system is 32bit or 64 bit.
IF EXIST %ProgramFiles(x86)%(
SET "PF=%ProgramFiles(x86)%"
) ELSE (
SET "PF=%ProgramFiles%"
)
rem Determine which version of office is being used.
FOR /r "%PF%\Microsoft Office\" %%a in (*.EXE) do (
IF "%%~nxa"=="WINWORD.EXE" (
set "p=%%~dpnxa"
)
)
IF EXIST "\\server\folder\file.dbf" (
%p% "\\server\folder\file.docx" /mDoMailMergeViewAllCG
)
Microsoft word opens with the proper document although the macro does not get executed.
While researching this topic, I have seen comments about using other methods such as powershell or auto macro. At this time I am not prepared to explore these options.
How can I get the new script to execute the macros?