Can I run VBA functions in Python?
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
|
show 2 more comments
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
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 usewin32 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
|
show 2 more comments
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
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
excel vba python-3.x excel-vba pywin32
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 usewin32 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
|
show 2 more comments
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 usewin32 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
|
show 2 more comments
1 Answer
1
active
oldest
votes
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered Nov 26 '18 at 13:39
PᴇʜPᴇʜ
22.2k42750
22.2k42750
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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