Here is another method. The ::: is harmless in VBS, and works like a comment in batch. What makes it particularly nice is you don't have to worry about escaping any of the VBS code.
I chose ::: because it is unlikely to appear elsewhere in your batch script; whereas : is used in batch labels, and :: is frequently used as a batch comment.
::: set shell = createobject("wscript.shell")
::: wscript.sleep(1000)
::: shell.sendkeys("blablabla")
::: Shell.SendKeys "{Enter}"
::: wscript.sleep(1000)
findstr /b ::: "%~f0" >"c:\folder\blablabla.vbs"
Here are some more options that only require a string to mark the beginning of the VBS, so they may be easier to write if dealing with a significant amount of VBS. Be sure to have exit /b before the VBS.
This second option is slower, and it will strip empty lines as currently written.
@echo off
setlocal
set "vbs=test.vbs"
for /f "delims=:" %%N in ('findstr /nb ":: begin VBS" "%~f0"') do set "skip=%%N"
(for /f usebackq^ skip^=%skip%^ delims^=^ eol^= %%A in ("%~f0") do echo %%A) >"%vbs%"
cscript /nologo "%vbs%"
del "%vbs%"
exit /b
:: begin VBS
set shell = createobject("wscript.shell")
wscript.sleep(1000)
shell.sendkeys("dir *.h*")
Shell.SendKeys "{Enter}"
wscript.sleep(1000)
This third option is fast, but MORE will convert tabs into a string of spaces.
@echo off
setlocal
set "vbs=test.vbs"
for /f "delims=:" %%N in ('findstr /nb ":: begin VBS" "%~f0"') do set "skip=%%N"
more +%skip% "%~f0" >"%vbs%"
cscript /nologo "%vbs%"
del "%vbs%"
exit /b
:: begin VBS
set shell = createobject("wscript.shell")
wscript.sleep(1000)
shell.sendkeys("dir *.h*")
Shell.SendKeys "{Enter}"
wscript.sleep(1000)