6

I am unable to find this information on the site using the search feature. And I have seen similar post On C# into Java and VBA into C# in this post

I raise this question because I think it's at least partially achievable if not all, and this would be a useful guide for others to do the conversion. Example question found on the net: here

Can ALL VBA be converted into VBS after some processing (Code changes)?

If not, what type of VBA program cannot be converted?

If yes, is there a vba program or any tools to do that automatically? If not, can someone kindly provide a full list of conversion rules from VBA to VBS? (I would like to write a VBA program to automatic this process if possible)

I am only aware of the following Rules (Please correct me if I am wrong)

  • Remove the type of a declaration Statement

VBA: Dim a as string
VBS: Dim a

VBA: Xlup
VBS: -4162

  • You cannot use redim someArray( A to B) syntax in VBS (VBS always start with 0 index)

VBA: Redim someArray( 1 to 10)
VBS: redim someArray(10)

  • You cannot specific iterator in a for loop in VBS

VBA:

For i = 1 to 10 
    'do something
next i 

VBS:

For i = 1 to 10 
    'do something
next 

Always need full qualified range in VBS (Just a demo.)

VBA: range("A1") = "Testing"

VBS: ExcelObj.Workbooks(1).Worksheets(1).Range("A1") = "Testing"

  • VBS cannot use VBA Collection type (Or Am I Not using the correct CreateObject?)

P.S. I am aware of this list and this list

I would appreciate any help, thanks in advance, and sorry for the long question._.

EDIT: I am working on a script myself, will update when I finish

Community
  • 1
  • 1
Larry
  • 2,764
  • 2
  • 25
  • 36
  • 1
    Larry, the user Tukai was converting most of the VBA codes to VBS. Believe he could provide you with some good tips. In the meantime take a look at this[article](http://www.digitalwindfire.com/posts/convert-vb6vba-code-to-vbs/) – bonCodigo Dec 28 '12 at 07:41
  • @bonCodigo Thanks for the reading, I will adopt the idea and add to my conversion script. Actually I was inspected by Tukai, and was checking if there's a available 80% converter would be nice. – Larry Dec 28 '12 at 07:45
  • 1
    Your list covers most of the conversion errors I've run across. It should also be noted that since VBS is not compiled, it does not support early binding like VBA does, so objects must be created using late binding – Fink Dec 28 '12 at 17:35
  • @Fink Thanks for the help, yeah, that's a good point. – Larry Dec 28 '12 at 17:37
  • Not a real question, yet here I find myself after googling said topic. – adolf garlic Jan 20 '16 at 16:08

0 Answers0