Long story short: I was asked to fix a broken macro, but I don't program w/ VB let alone use excel more than I'm forced to. I can read and understand whats broken with the macro, but I'd rather improve it to prevent the next poor intern from having to fix it.
I wrote up some pseudo code to get my idea about what I'm looking to do across.
I'm just looking to save a copy of the workbook when it opens. The copy should have the same name as the workbook that opens with the extension .tmp.xls. I actually want it to be in .xls (97-2003).## when workbook opens run the following code save($thisworkbook) as ('C:/path1/path2/' . $thisworkbook['name'] . '.tmp.xls') #I think the command is actually shell for VBA #open a shell run python, pass the workbook name as an argument shell('C:/python25/python.exe $thisworkboo_name.tmp.xls') #I don't want it to ask if I'm going to save it, that's what the first line is for close(thisworkbook); make_excel_go_away();
Open a shell, run python, and pass the workbook name as an argument.
I've tried searching for subs written by other people to do these tasks, but I just can't seem to get it to work. I hit the beginner tuts and still made no progress.
Edit: there are no other macros in the workbook.
Edit2: code tags
Last edited by eval(BadCode); 09-02-2010 at 10:43 PM.
Something like...
Sub Test() ThisWorkbook.SaveCopyAs ("C:/path1/path2/" & Right(ThisWorkbook.Name, Len(ThisWorkbook.Name - 3)) & ".tmp.xls") Shell ("C:/python25/python.exe, C:/path1/path2/" & Right(ThisWorkbook.Name, Len(ThisWorkbook.Name - 3)) & ".tmp.xls") ThisWorkbook.Saved = True ThisWorkbook.Close Application.Quit End Sub
Martin
Eighty Twenty Spreadsheet Automation http://homepage.ntlworld.com/martin.rice1/ for all your Excel customisation and consulting needs.
If my solution has saved you time and/or money, please consider donating to Cancer Research UK.
is equivalent to:ThisWorkbook.Close Application.Quit
(i.e. exactly as requested)close(thisworkbook); make_excel_go_away();
But this will not work beautifully if the user has other workbooks open.
maybe:
(replacing both lines quoted)If application.workbooks.count < 3 and not application.workbooks("PERSONAL.XLS") is nothing then application.quit else thisworkbook.close end if
HTH
Last edited by Cheeky Charlie; 09-04-2010 at 11:25 AM. Reason: better code
CC
If you feel really indebted please consider a donation to charity. My preferred charity is ActionAid but there are plenty of worthy alternatives.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks