0

I have an Excel file with several macros in it, some call SolidWorks, some with PDM, some call acrobat pro. Several different users will use this spreadsheet, for different reasons, a few won't have SolidWorks, some won't have Acrobat Pro, this is causing library reference missing in some computers, and if missing any reference, none of the macros will run. I search for an easy solution like just don't run the missing library macro but couldn't find it. My next thinking was to add the libraries to the vault and all could run from there, not possible. maybe if I just copy the reference files to each computer would work, and it did, even without acrobat, just creating the folder path with the *.tlb in it works like a charm, question now is how to create all those folder structures with all referenced files in all computers. Batch file. As I could find online and examples, this should work but it's not and I don't know why, even used some bat test tools and all say is good. is some network configuration? privilege issues? here is part of the code. the rest just repeat for Solidworks and PDM files.

@ECHO OFF
IF EXIST "C:\Program Files (x86)\Adobe\" (
) ELSE (
mkdir "C:\Program Files (x86)\Adobe")
IF EXIST "C:\Program Files (x86)\Adobe\Acrobat 11.0\" (
)ELSE(
mkdir "C:\Program Files (x86)\Adobe\Acrobat 11.0")
IF EXIST "C:\Program Files (x86)\Adobe\Acrobat 11.0\Acrobat\" (
)ELSE(
mkdir "C:\Program Files (x86)\Adobe\Acrobat 11.0\Acrobat")
IF EXIST "C:\Program Files (x86)\Adobe\Acrobat 11.0\Acrobat\acrobat.tlb"(
)ELSE()
xcopy "\\eng\Lib\acrobat.tlb" "C:\Program Files (x86)\Adobe\Acrobat 11.0\Acrobat\"
ECHO "dONE!"

I'm trying to check if the folder structure exists, if not create the folder structure as is in excel reference and copy the file, it just doesn't work. How do I make it work? Is there a better way?

braX
  • 11,506
  • 5
  • 20
  • 33
jsalale
  • 11
  • 3
  • 2
    If missing references are a problem you can use late binding and test for the ability to create certain objects as a way to know which users have which installs. https://learn.microsoft.com/en-us/previous-versions/office/troubleshoot/office-developer/binding-type-available-to-automation-clients, https://peltiertech.com/Excel/EarlyLateBinding.html – Tim Williams Sep 12 '20 at 01:11
  • Have you ever typed `if /?` into a Command Prompt window? – aschipfl Sep 12 '20 at 08:05
  • The installer of Adobe Acrobat follows the Microsoft guidelines for [Application Registration](https://learn.microsoft.com/en-us/windows/win32/shell/app-registration). For that reason a `reg query` can be used embedded in a `for /F` loop to get the program files folder of Adobe Acrobat if it is installed at all. There is no need to search around using the default paths and hoping that Adobe Acrobat is really installed in one of the default paths. – Mofi Sep 12 '20 at 10:19
  • @TimWilliams - Thank you for the hint, very useful for acrobat because I create an object, but for SolidWorks PDM is different, `Dim vault As New EdmLib.EdmVault5 vault.LoginAuto "MyVault", 0 If vault.IsLoggedIn Then` would be possible to use late binding with something like that? – jsalale Sep 12 '20 at 16:38
  • Try `Dim vault As Object: Set vault = CreateObject("EdmLib.EdmVault5")` – Tim Williams Sep 12 '20 at 17:27

1 Answers1

0

First, We should run script with Administrator permissions.
Then, I used For loop to processing each folders.

Try this code :

@Echo off
net session >nul 2>&1 && goto :admintasks
MSHTA "javascript: var shell = new ActiveXObject('shell.application'); shell.ShellExecute('%~nx0', '', '', 'runas', 1);close();"
exit /b
:admintasks
SETLOCAL EnableDelayedExpansion
cd /d "%~dp0"
Set "a=%ProgramFiles(x86)%\Adobe"
Set "b=%ProgramFiles(x86)%\Adobe\Acrobat 11.0"
Set "c=%ProgramFiles(x86)%\Adobe\Acrobat 11.0\Acrobat"
Set "d=%ProgramFiles(x86)%\Adobe\Acrobat 11.0\Acrobat\acrobat.tlb"
FOR %%A IN ("!a!" "!b!" "!c!") DO (
if Not exist %%A mkdir %%A
)
IF Not EXIST "%d%" xcopy "\\eng\Lib\acrobat.tlb" "C:\Program Files (x86)\Adobe\Acrobat 11.0\Acrobat\"
ECHO "Done!"

For understanding the used commands and how they work, open a cmd window, execute there the following commands.

  • for /?
  • goto /?
  • if /?
  • set /?
  • setlocal /?
  • cd /?