Jul-25-2017, 09:55 AM
HI all! I am new in Python coding and I have a problem in the below:
What I am trying to do is:
1) Run the "Disability_Run" macro from the Active excel WB that I have already open;
2) Defining the WB name and its location in a variable called absPath;
3) Close the open Excel WB;
4) Open the Excel WB again trying to use the absPath variable instead of typing down the whole WB name and location.
The code works fine until the last line:
Even though I do not receive any error message I am not able to open again the file with this line once has been closed.
It is very important for me not making any reference to the name of the WB as the name of the file will change every quarter.
Thanks in advance for your help.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
object = win32com.client.Dispatch( 'Excel.Application' ) object .visible = 1 object .Run( "Disability_Run" ) print ( "Macro ran successfully!" ) wbName = object .ActiveWorkbook.Name absPath = os.path.abspath(wbName) print ( "absPath=" ,absPath) print ( "Active WB:" , wbName) for wb in object .Workbooks: print ( "WB:" ,wb.Name) wb.Save() #The loop above saves all the workbooks that are open object .quit() #Open the Excel file again object = win32com.client.Dispatch( 'Excel.Application' ) object .visible = 1 wb1 = object .Workbooks. open ( 'C:\\Program Files\\SunGard\Prophet Excel Reporting\\Altsta_14b\\ExcelRPM.xlam' ) wb2 = object .Workbooks. open ( 'C:\\Program Files\\SunGard\Prophet Excel Reporting\\Altsta_14b\\Perms.xlam' ) wb3 = object .Workbooks. open ( 'C:\\Program Files\\SunGard\Prophet Excel Reporting\\Altsta_14b\\ProphetQueries.xlam' ) object .RegisterXLL( 'C:\\Program Files\\SunGard\\Prophet Excel Reporting\\x86\\GleanExcelResults.xll' ) #The above makes not receive the error message about the 'GleanReleaseComponentLocks' macro, because it imports the Prophet Add-in. However still not receive the prophet add in wb = object .Workbooks. open (absPath) |
1) Run the "Disability_Run" macro from the Active excel WB that I have already open;
2) Defining the WB name and its location in a variable called absPath;
3) Close the open Excel WB;
4) Open the Excel WB again trying to use the absPath variable instead of typing down the whole WB name and location.
The code works fine until the last line:
1 |
wb = object .Workbooks. open (absPath) |
It is very important for me not making any reference to the name of the WB as the name of the file will change every quarter.
Thanks in advance for your help.