The Application.PromptForSummaryInfo member in Excel’s object model is a method that displays the “Properties” dialog box, allowing users to view or edit the summary information and statistics of the active workbook. This dialog box includes details such as the title, subject, author, manager, company, category, keywords, comments, and hyperlink base. In xlwings, this functionality can be accessed to programmatically trigger this dialog, which is useful for automating document property management or prompting users to input metadata before saving or distributing a workbook.
Syntax in xlwings:
The method is called via the Application object. The xlwings API syntax is:
app.api.PromptForSummaryInfo
Here, app refers to the xlwings Application object. This method does not take any parameters and does not return a value. It simply opens the dialog box modally, meaning code execution pauses until the user closes the dialog. The method corresponds to the VBA Application.PromptForSummaryInfo method.
Parameters:
The method has no parameters. In VBA, it is called without arguments, and the same applies in xlwings through the .api attribute, which exposes the underlying Excel object model.
Example Usage:
Below is a practical xlwings code example that starts an Excel instance, opens a workbook, and then displays the “Properties” dialog box to allow the user to edit summary information. This can be integrated into scripts for data preparation workflows where document metadata is required.
import xlwings as xw
# Start a new Excel application (visible to see the dialog)
app = xw.App(visible=True)
# Open an existing workbook or create a new one
wb = app.books.open('example.xlsx') # Replace with your file path
# Display the PromptForSummaryInfo dialog
app.api.PromptForSummaryInfo
# The code will pause here while the user interacts with the dialog.
# After closing the dialog, you can continue with other operations, e.g., save the workbook.
wb.save()
print("Workbook properties have been updated.")
# Close the workbook and quit Excel
wb.close()
app.quit()
Leave a Reply