transform .bat in Vba Macro

User avatar
sal21
PlatinumLounger
Posts: 4402
Joined: 26 Apr 2010, 17:36

transform .bat in Vba Macro

Post by sal21 »

is possible to transform this .bat in a macro code?

Code: Select all

@echo off
cls
IF EXIST C:\SPORTELL\SPORTLIM.EXE GOTO ELIMINA
GOTO NUOVO
:ELIMINA
echo.
echo.
echo ********* RILEVATA VERSIONE PRECEDENTE DEL PROGRAMMA ********
echo ********* ELIMINAZIONE DELLA VECCHIA VERSIONE ...    ********

DEL C:\SPORTELL\*.DBF
DEL C:\SPORTELL\*.NTX
DEL C:\SPORTELL\*.INI
DEL C:\SPORTELL\*.EXE
DEL C:\SPORTELL\*.ICO
DEL C:\SPORTELL\S*.BAT
GOTO AGGIORNA

:NUOVO
md c:\sportell
GOTO AGGIORNA

:AGGIORNA
CLS
c:
echo.
echo.
echo ********* DECOMPRESSIONE DEL FILE SPORTELLI E CARICAMENTO ********
echo ********* PROGRAMMA DI GESTIONE, PREGO ATTENDERE ........ ********
CALL sportl.EXE -o \SPORTELL
cls
echo.
echo ********* OPERAZIONE COMPLETATA *********
dir c:\sportell
pause
goto TRE
:DUE
echo.
echo.
echo      ******       RINUNCIA ALL'OPERAZIONE        *********
echo      *******    INSTALLAZIONE NON EFFETTUATA     *********
echo.
:TRE
cls

User avatar
HansV
Administrator
Posts: 78774
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: transform .bat in Vba Macro

Post by HansV »

I'm not sure this will work, you'll have to try it:

Code: Select all

Sub Sal21()
    If Dir("C:\SPORTELL\SPORTLIM.EXE") = "" Then
        MkDir "C:\SPORTELL"
    Else
        Kill "C:\SPORTELL\*.DBF"
        Kill "C:\SPORTELL\*.NTX"
        Kill "C:\SPORTELL\*.INI"
        Kill "C:\SPORTELL\*.EXE"
        Kill "C:\SPORTELL\*.ICO"
        Kill "C:\SPORTELL\S*.BAT"
    End If
    Shell "sportl.EXE -o \SPORTELL"
End Sub
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4402
Joined: 26 Apr 2010, 17:36

Re: transform .bat in Vba Macro

Post by sal21 »

HansV wrote:I'm not sure this will work, you'll have to try it:

Code: Select all

Sub Sal21()
    If Dir("C:\SPORTELL\SPORTLIM.EXE") = "" Then
        MkDir "C:\SPORTELL"
    Else
        Kill "C:\SPORTELL\*.DBF"
        Kill "C:\SPORTELL\*.NTX"
        Kill "C:\SPORTELL\*.INI"
        Kill "C:\SPORTELL\*.EXE"
        Kill "C:\SPORTELL\*.ICO"
        Kill "C:\SPORTELL\S*.BAT"
    End If
    Shell "sportl.EXE -o \SPORTELL"
End Sub

before to post a solution a test a script to exceute a bat via sheel...

but this code dont have effect!

Code: Select all

Dim shell As Object
Set shell = CreateObject("wscript.shell")
shell.Run "C:\TABULATI\SPORTELLI\install.bat", vbHide
Set shell = Nothing

User avatar
HansV
Administrator
Posts: 78774
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: transform .bat in Vba Macro

Post by HansV »

Are you sure? Similar code works for me.
You can also try

Code: Select all

    Shell "cmd /c C:\TABULATI\SPORTELLI\install.bat", vbHide
(Please note that Shell is NOT declared here - this code uses the built-in VBA function Shell)
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4402
Joined: 26 Apr 2010, 17:36

Re: transform .bat in Vba Macro

Post by sal21 »

HansV wrote:Are you sure? Similar code works for me.
You can also try

Code: Select all

    Shell "cmd /c C:\TABULATI\SPORTELLI\install.bat", vbHide
(Please note that Shell is NOT declared here - this code uses the built-in VBA function Shell)
WOW!!!!
wORK NOW.

in other case i use the first solution Sub Sal21(i this is professional)...

But i need to save the uncompress file of .exe instead in c:\sportell but in c:\mydir\sportelli\...
i think i need to change this line
Shell "sportl.EXE -o SPORTELL"
to set the new dir or not?

User avatar
HansV
Administrator
Posts: 78774
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: transform .bat in Vba Macro

Post by HansV »

You can change

Code: Select all

    Shell "sportl.EXE -o \SPORTELL"
to

Code: Select all

    Shell "sportl.EXE -o \mydir\sportelli"
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4402
Joined: 26 Apr 2010, 17:36

Re: transform .bat in Vba Macro

Post by sal21 »

HansV wrote:You can change

Code: Select all

    Shell "sportl.EXE -o \SPORTELL"
to

Code: Select all

    Shell "sportl.EXE -o \mydir\sportelli"
Used:
Shell "C:\TABULATI\SPORTELLI\sportl.exe -o \C:\TABULATI\SPORTELLI\FILE\"

but nothing is copied in ...\FILE\

User avatar
HansV
Administrator
Posts: 78774
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: transform .bat in Vba Macro

Post by HansV »

If you explicitly mention the drive C:, you shouldn't place \ before it:

Code: Select all

Shell "C:\TABULATI\SPORTELLI\sportl.exe -o C:\TABULATI\SPORTELLI\FILE\"
Does the folder C:\TABULATI\SPORTELLI\FILE exist? If not, you should create it, either manually or using

Code: Select all

    MkDir C:\TABULATI\SPORTELLI\FILE
before calling sportl.exe.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4402
Joined: 26 Apr 2010, 17:36

Re: transform .bat in Vba Macro

Post by sal21 »

HansV wrote:If you explicitly mention the drive C:, you shouldn't place \ before it:

Code: Select all

Shell "C:\TABULATI\SPORTELLI\sportl.exe -o C:\TABULATI\SPORTELLI\FILE\"
Does the folder C:\TABULATI\SPORTELLI\FILE exist? If not, you should create it, either manually or using

Code: Select all

    MkDir C:\TABULATI\SPORTELLI\FILE
before calling sportl.exe.
this line dont copy nothing in ...\FILE\
Shell "C:\TABULATI\SPORTELLI\sportl.exe -o C:\TABULATI\SPORTELLI\FILE\"

User avatar
HansV
Administrator
Posts: 78774
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: transform .bat in Vba Macro

Post by HansV »

What happens if you open a Command Prompt window, type

C:\TABULATI\SPORTELLI\sportl.exe -o C:\TABULATI\SPORTELLI\FILE\

and then press Enter?
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4402
Joined: 26 Apr 2010, 17:36

Re: transform .bat in Vba Macro

Post by sal21 »

HansV wrote:What happens if you open a Command Prompt window, type

C:\TABULATI\SPORTELLI\sportl.exe -o C:\TABULATI\SPORTELLI\FILE\

and then press Enter?

:groan:

SOLVED!
now work, fine.

invisible space in commend line :sad: :grin: