Can I run VBA functions in Python?












0















Is it possible to import and run VBA functions in Python?



For example, let mymodule.bas include the following function:



Function AddTwoNumbers(ByVal Alpha As Variant, ByVal Beta As Variant) As Variant
AddTwoNumbers = (Alpha + Beta)
End Function


Is there an extension I can use to interface to such function using Python? I was thinking of using pywin32 but it is not clear to me whether this only works with vba functions inside a MS Excel spreadsheet.










share|improve this question




















  • 1





    What is a "standalone VBA file"? That doesn't exist. VBA is always a part of an Excel, Word or other MS Office file (it cannot be stand alone). Do you mean VBScript instead? But this is a completely different language! Be very clear about the terms you use. Also please be more specific what you mean with "import the module"? You want to translate it into python or do you want to call a function? Your question is very unclear.

    – Pᴇʜ
    Nov 26 '18 at 12:25








  • 1





    @Pᴇʜ, I believe OP is talking specifically about the exported VBA file which is a .bas file. So: "Yes, a standalone VBA file" which is useless unless imported into an office application's VBE.

    – JNevill
    Nov 26 '18 at 13:31






  • 1





    OP, that being said, this doesn't make a lick of sense. VBA only works inside of an MS Office environment. You can't just steal the VBA from your VBE (Even exporting it) and expect it to run anywhere. It won't. It will only run inside that environment. Use a library for Python that is meant to work with the Office application you are wanting to automate.

    – JNevill
    Nov 26 '18 at 13:32













  • For instance, this question has a brief write up on how to use win32 extension in python. You will have to rewrite your VBA to work in Python though, there will be no copy/paste way of doing this.

    – JNevill
    Nov 26 '18 at 13:36











  • How do you run your .bas file from commandline?

    – CristiFati
    Nov 26 '18 at 17:01
















0















Is it possible to import and run VBA functions in Python?



For example, let mymodule.bas include the following function:



Function AddTwoNumbers(ByVal Alpha As Variant, ByVal Beta As Variant) As Variant
AddTwoNumbers = (Alpha + Beta)
End Function


Is there an extension I can use to interface to such function using Python? I was thinking of using pywin32 but it is not clear to me whether this only works with vba functions inside a MS Excel spreadsheet.










share|improve this question




















  • 1





    What is a "standalone VBA file"? That doesn't exist. VBA is always a part of an Excel, Word or other MS Office file (it cannot be stand alone). Do you mean VBScript instead? But this is a completely different language! Be very clear about the terms you use. Also please be more specific what you mean with "import the module"? You want to translate it into python or do you want to call a function? Your question is very unclear.

    – Pᴇʜ
    Nov 26 '18 at 12:25








  • 1





    @Pᴇʜ, I believe OP is talking specifically about the exported VBA file which is a .bas file. So: "Yes, a standalone VBA file" which is useless unless imported into an office application's VBE.

    – JNevill
    Nov 26 '18 at 13:31






  • 1





    OP, that being said, this doesn't make a lick of sense. VBA only works inside of an MS Office environment. You can't just steal the VBA from your VBE (Even exporting it) and expect it to run anywhere. It won't. It will only run inside that environment. Use a library for Python that is meant to work with the Office application you are wanting to automate.

    – JNevill
    Nov 26 '18 at 13:32













  • For instance, this question has a brief write up on how to use win32 extension in python. You will have to rewrite your VBA to work in Python though, there will be no copy/paste way of doing this.

    – JNevill
    Nov 26 '18 at 13:36











  • How do you run your .bas file from commandline?

    – CristiFati
    Nov 26 '18 at 17:01














0












0








0








Is it possible to import and run VBA functions in Python?



For example, let mymodule.bas include the following function:



Function AddTwoNumbers(ByVal Alpha As Variant, ByVal Beta As Variant) As Variant
AddTwoNumbers = (Alpha + Beta)
End Function


Is there an extension I can use to interface to such function using Python? I was thinking of using pywin32 but it is not clear to me whether this only works with vba functions inside a MS Excel spreadsheet.










share|improve this question
















Is it possible to import and run VBA functions in Python?



For example, let mymodule.bas include the following function:



Function AddTwoNumbers(ByVal Alpha As Variant, ByVal Beta As Variant) As Variant
AddTwoNumbers = (Alpha + Beta)
End Function


Is there an extension I can use to interface to such function using Python? I was thinking of using pywin32 but it is not clear to me whether this only works with vba functions inside a MS Excel spreadsheet.







excel vba python-3.x excel-vba pywin32






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 17:24







Kievit

















asked Nov 26 '18 at 9:41









KievitKievit

374




374








  • 1





    What is a "standalone VBA file"? That doesn't exist. VBA is always a part of an Excel, Word or other MS Office file (it cannot be stand alone). Do you mean VBScript instead? But this is a completely different language! Be very clear about the terms you use. Also please be more specific what you mean with "import the module"? You want to translate it into python or do you want to call a function? Your question is very unclear.

    – Pᴇʜ
    Nov 26 '18 at 12:25








  • 1





    @Pᴇʜ, I believe OP is talking specifically about the exported VBA file which is a .bas file. So: "Yes, a standalone VBA file" which is useless unless imported into an office application's VBE.

    – JNevill
    Nov 26 '18 at 13:31






  • 1





    OP, that being said, this doesn't make a lick of sense. VBA only works inside of an MS Office environment. You can't just steal the VBA from your VBE (Even exporting it) and expect it to run anywhere. It won't. It will only run inside that environment. Use a library for Python that is meant to work with the Office application you are wanting to automate.

    – JNevill
    Nov 26 '18 at 13:32













  • For instance, this question has a brief write up on how to use win32 extension in python. You will have to rewrite your VBA to work in Python though, there will be no copy/paste way of doing this.

    – JNevill
    Nov 26 '18 at 13:36











  • How do you run your .bas file from commandline?

    – CristiFati
    Nov 26 '18 at 17:01














  • 1





    What is a "standalone VBA file"? That doesn't exist. VBA is always a part of an Excel, Word or other MS Office file (it cannot be stand alone). Do you mean VBScript instead? But this is a completely different language! Be very clear about the terms you use. Also please be more specific what you mean with "import the module"? You want to translate it into python or do you want to call a function? Your question is very unclear.

    – Pᴇʜ
    Nov 26 '18 at 12:25








  • 1





    @Pᴇʜ, I believe OP is talking specifically about the exported VBA file which is a .bas file. So: "Yes, a standalone VBA file" which is useless unless imported into an office application's VBE.

    – JNevill
    Nov 26 '18 at 13:31






  • 1





    OP, that being said, this doesn't make a lick of sense. VBA only works inside of an MS Office environment. You can't just steal the VBA from your VBE (Even exporting it) and expect it to run anywhere. It won't. It will only run inside that environment. Use a library for Python that is meant to work with the Office application you are wanting to automate.

    – JNevill
    Nov 26 '18 at 13:32













  • For instance, this question has a brief write up on how to use win32 extension in python. You will have to rewrite your VBA to work in Python though, there will be no copy/paste way of doing this.

    – JNevill
    Nov 26 '18 at 13:36











  • How do you run your .bas file from commandline?

    – CristiFati
    Nov 26 '18 at 17:01








1




1





What is a "standalone VBA file"? That doesn't exist. VBA is always a part of an Excel, Word or other MS Office file (it cannot be stand alone). Do you mean VBScript instead? But this is a completely different language! Be very clear about the terms you use. Also please be more specific what you mean with "import the module"? You want to translate it into python or do you want to call a function? Your question is very unclear.

– Pᴇʜ
Nov 26 '18 at 12:25







What is a "standalone VBA file"? That doesn't exist. VBA is always a part of an Excel, Word or other MS Office file (it cannot be stand alone). Do you mean VBScript instead? But this is a completely different language! Be very clear about the terms you use. Also please be more specific what you mean with "import the module"? You want to translate it into python or do you want to call a function? Your question is very unclear.

– Pᴇʜ
Nov 26 '18 at 12:25






1




1





@Pᴇʜ, I believe OP is talking specifically about the exported VBA file which is a .bas file. So: "Yes, a standalone VBA file" which is useless unless imported into an office application's VBE.

– JNevill
Nov 26 '18 at 13:31





@Pᴇʜ, I believe OP is talking specifically about the exported VBA file which is a .bas file. So: "Yes, a standalone VBA file" which is useless unless imported into an office application's VBE.

– JNevill
Nov 26 '18 at 13:31




1




1





OP, that being said, this doesn't make a lick of sense. VBA only works inside of an MS Office environment. You can't just steal the VBA from your VBE (Even exporting it) and expect it to run anywhere. It won't. It will only run inside that environment. Use a library for Python that is meant to work with the Office application you are wanting to automate.

– JNevill
Nov 26 '18 at 13:32







OP, that being said, this doesn't make a lick of sense. VBA only works inside of an MS Office environment. You can't just steal the VBA from your VBE (Even exporting it) and expect it to run anywhere. It won't. It will only run inside that environment. Use a library for Python that is meant to work with the Office application you are wanting to automate.

– JNevill
Nov 26 '18 at 13:32















For instance, this question has a brief write up on how to use win32 extension in python. You will have to rewrite your VBA to work in Python though, there will be no copy/paste way of doing this.

– JNevill
Nov 26 '18 at 13:36





For instance, this question has a brief write up on how to use win32 extension in python. You will have to rewrite your VBA to work in Python though, there will be no copy/paste way of doing this.

– JNevill
Nov 26 '18 at 13:36













How do you run your .bas file from commandline?

– CristiFati
Nov 26 '18 at 17:01





How do you run your .bas file from commandline?

– CristiFati
Nov 26 '18 at 17:01












1 Answer
1






active

oldest

votes


















1














The answer to your question is:




  • It is not possible to import a mymodule.bas (that was exported from VBA) into Python.

  • It is not possible to run a VBA code (mymodule.bas) that was exported from VBA stand alone.

  • There is no way to automatically translate VBA into Python.


Possibilities you have:




  • Manually re-write your code in Python using a library to access Excel files: Automation Excel from Python






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53478319%2fcan-i-run-vba-functions-in-python%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    The answer to your question is:




    • It is not possible to import a mymodule.bas (that was exported from VBA) into Python.

    • It is not possible to run a VBA code (mymodule.bas) that was exported from VBA stand alone.

    • There is no way to automatically translate VBA into Python.


    Possibilities you have:




    • Manually re-write your code in Python using a library to access Excel files: Automation Excel from Python






    share|improve this answer




























      1














      The answer to your question is:




      • It is not possible to import a mymodule.bas (that was exported from VBA) into Python.

      • It is not possible to run a VBA code (mymodule.bas) that was exported from VBA stand alone.

      • There is no way to automatically translate VBA into Python.


      Possibilities you have:




      • Manually re-write your code in Python using a library to access Excel files: Automation Excel from Python






      share|improve this answer


























        1












        1








        1







        The answer to your question is:




        • It is not possible to import a mymodule.bas (that was exported from VBA) into Python.

        • It is not possible to run a VBA code (mymodule.bas) that was exported from VBA stand alone.

        • There is no way to automatically translate VBA into Python.


        Possibilities you have:




        • Manually re-write your code in Python using a library to access Excel files: Automation Excel from Python






        share|improve this answer













        The answer to your question is:




        • It is not possible to import a mymodule.bas (that was exported from VBA) into Python.

        • It is not possible to run a VBA code (mymodule.bas) that was exported from VBA stand alone.

        • There is no way to automatically translate VBA into Python.


        Possibilities you have:




        • Manually re-write your code in Python using a library to access Excel files: Automation Excel from Python







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 26 '18 at 13:39









        PᴇʜPᴇʜ

        22.2k42750




        22.2k42750
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53478319%2fcan-i-run-vba-functions-in-python%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Contact image not getting when fetch all contact list from iPhone by CNContact

            count number of partitions of a set with n elements into k subsets

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks