473,327 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Use macros in Excel via win32com

I'm creating an excel document dynamically from scratch using Python
and the win32com module. All is well, but now I need to add a macro to
the spreadsheet and run it (to enable some sorting features in the
spreadsheet). I think I know how to run a macro once it's installed
(using the Run method of the excel application object...I think), but I
can't figure out how to "install" the VBA macro code into the
spreadsheet to begin with from my Python script.
Any tips appreciated.

Thanks,
Chris

Jul 18 '05 #1
5 4097

"chris" <ch***************@gmail.com> wrote:
I'm creating an excel document dynamically from scratch using Python
and the win32com module. All is well, but now I need to add a macro to
the spreadsheet and run it (to enable some sorting features in the
spreadsheet). I think I know how to run a macro once it's installed
(using the Run method of the excel application object...I think), but I
can't figure out how to "install" the VBA macro code into the
spreadsheet to begin with from my Python script.
Any tips appreciated.


Here is a manual solution for Excel 2003. At the bottom of the spreadsheet,
right-click on one of the tabs (default names sheet1 sheet2 sheet3). Click
"view code" on the menu, which should bring up a Microsoft Visual Basic editor.
Select Module from the Insert menu at the top, and paste the VBA code there.

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Jul 18 '05 #2
Thanks, but the problem is that I need to create the entire Excel
document from scratch, dynamically, via the Python script. I want the
script to add the macro code.

-Chris

Jul 18 '05 #3
chris wrote:
I'm creating an excel document dynamically from scratch using Python
and the win32com module. All is well, but now I need to add a macro to
the spreadsheet and run it (to enable some sorting features in the
spreadsheet). I think I know how to run a macro once it's installed
(using the Run method of the excel application object...I think), but I
can't figure out how to "install" the VBA macro code into the
spreadsheet to begin with from my Python script.
Any tips appreciated.


Make a xla in Excel including your VBA macro first and then create your
spreadshet from python using that xla as template.

--
Greg

Jul 18 '05 #4
chris,
I'm creating an excel document dynamically from scratch using Python
and the win32com module. All is well, but now I need to add a macro to
the spreadsheet and run it (to enable some sorting features in the
spreadsheet).


I recommend to create the excel document not from scratch but from a
template.

I learned from experience that it is speadier to have all the static parts
allready prepared - and especially diagrams and macros are MUCH easier to
handle if allready in the programm

Harald
Jul 18 '05 #5
This makes sense. Thanks for the ideas.

Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet...
3
by: calfdog | last post by:
Hello, I have been doing some experimenting with Automating Internet Explorer for testing. I would like to read from Excel and use the data to set the values of my text boxes on my web forms....
1
by: koia | last post by:
Hi, I have a problem with adding attributes to a Line in an Excel drawing using the Python win32com interface. From recording in Excel I get the Macro: Sub Makro1()...
3
by: implicate_order | last post by:
Greetings, I'm new to python and am in the process of writing a script to parse some CSV data, spread it across multiple Excel worksheets and then generate charts. I searched the internet to...
3
by: dan_roman | last post by:
Hi, I developed a script with a nice interface in Tkinter that allows me to edit some formulas and to generate an Excel worksheet with VBA macros within it. The script runs perfectlly in Office...
4
by: michael.pearmain | last post by:
Hi Experts, Looking for a very quick bit on of advice on how to make some python code run. I'm a newbie to both VBA and Python, so i apologise if this is very easy but i'm about to tear my hair...
3
by: Lance Hoffmeyer | last post by:
Hi all, I am trying to find the last used column in an excel sheet using win32com: lastcol = sh.UsedRange.Columns.Count works, but only if there is no formatting. I want to allow formatting...
2
by: Ray | last post by:
Hi, I need to use cell's background color. when I record a macro from excel, it shows: Rows("7:7").Select With Selection.Interior .ColorIndex = 8 .Pattern = xlSolid
1
by: Girish | last post by:
Hi, I want to embed a txt document into an excel using python. Here is my code, but i get an error message =================================================== Traceback (most recent call...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.