Click here to Skip to main content
11,634,568 members (73,988 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: Python Excel
i am working project where ANAYS WORKBENCH is interfaced with MS EXCEL via python script.

    # IronPython imports to enable Excel interop
    import clr
    import Microsoft.Office.Interop.Excel as Excel
    workingDir = AbsUserPathName("C:\Users\shreepal\Downloads\Compressed/")
    def updateHandler():
    	# Define key ranges in the Workbook
    	lenCell = worksheet.Range["B6"]
    	ldCell = worksheet.Range["B7"]
    	dfCell = worksheet.Range["B8"]
    	# Get the Workbench Parameters
    	lenParam = Parameters.GetParameter(Name="P1")
    	ldParam = Parameters.GetParameter(Name="P2")
    	dfParam = Parameters.GetParameter(Name="P3")
    	# Assign values to the input parameters
    	lenParam.Expression = lenCell.Value2.ToString()
    	ldParam.Expression = ldCell.Value2.ToString() 
    	# Mark the deformation parameter as updating in the workbook
    	# Run the project update
    	# Update the workbook value from the WB parameter
    	dfCell.Value2 = dfParam.Value.Value
    # Open the Workbench Project
    Open(FilePath = workingDir + "ExcelParameterScripting.wbpj")
    # Open Excel and the workbook
    ex = Excel.ApplicationClass()
    ex.Visible = True
    workbook = ex.Workbooks.Open(workingDir + "ParameterExample.xlsm")
    #Apply the update handler to the workbook button
    OLEbutton = worksheet.OLEObjects("CommandButton1")
    OLEbutton.Object.CLICK += updateHandler

This code will launch Excel and Workbench and add the command to execute the update script when we push the button in excel.

**problem is that the action to update the spreadsheet and model is assigned as an OLEObject to the button. Unfortunately this is only active when the script is running. Once it is done the click action is removed, and the button becomes useless. can anyone provide me the code for this button which will able to update the system as many times it is clicked?**
Posted 11-Apr-13 0:15am
Edited 11-Apr-13 3:20am
(no name)187.2K

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 8,736
1 Sergey Alexandrovich Kryukov 8,359
2 Mika Wendelius 6,845
3 F-ES Sitecore 2,354
4 Suvendu Shekhar Giri 2,205

Advertise | Privacy | Mobile
Web02 | 2.8.150728.1 | Last Updated 11 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100