MS - Error with VBA Sub to write a binary file

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
Massi
Newbie
Posts: 6
Joined: Fri Jan 10, 2020 9:05 pm

MS - Error with VBA Sub to write a binary file

Post by Massi » Mon Mar 16, 2020 12:59 pm

Hello,
I have a trouble with this little subroutine in VBA (see file script attached)
I have tested it first in real VBA environment and works ok.

In MS I do get an error.
----- Macro Scheduler--------
Microsoft VBScript Compilation error: 1025
Expected end of statement
Line 37, Colum 16

VBStart
Sub WriteBin()
Dim FileName
Dim Testvar
Dim FileNo

FileName = "Q:\test.bin"
Testvar = 4
FileNo = FreeFile
Open FileName For Binary Lock Read Write As #FileNo
Put #FileNo, , Testvar
Close #FileNo
End Sub
VBEnd
Vbrun>WriteBin

- What I do wrong?
- Do you have any guideline how to vrite VBScript code?
often I have to find tricks to make it working :D

Thanks
Massimo

User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: MS - Error with VBA Sub to write a binary file

Post by Marcus Tettmar » Mon Mar 16, 2020 1:25 pm

Macro Scheduler supports VBScript not VBA. The code inside a VBSTART and VBEND block needs to be VBScript not VBA - the two are very different. A major difference is that VBA has context - it sits within an application like Excel or Word and therefore knows about those apps whereas VBScript doesn't.

See:
https://help.mjtnet.com/article/19-conv ... o-vbscript
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Massi
Newbie
Posts: 6
Joined: Fri Jan 10, 2020 9:05 pm

Re: MS - Error with VBA Sub to write a binary file

Post by Massi » Mon Mar 16, 2020 3:04 pm

ok.
thanks for the refences and explanations
massimo

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts