Click here to Skip to main content
13,092,862 members (97,375 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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
Updated 11-Apr-13 3:20am
Maciej Los255.5K

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 11 Apr 2013
Copyright © CodeProject, 1999-2017
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