I'm trying to open file select dialog box from excel cell to capture file path. The excel is being created by OpenXML. I noticed we cannot use VBA in OpenXML. any suggestions how to implement this would be helpful. Thanks in Advance.
Loading
I'm trying to open file select dialog box from excel cell to capture file path. The excel is being created by OpenXML. I noticed we cannot use VBA in OpenXML. any suggestions how to implement this would be helpful. Thanks in Advance.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Karthik SPosted Jun 2, 2023, 9:36 AM
Thanks. But how can we open file select dialog box on retry button click. Also is there a way to achieve file select dialog box using interop ?Thanks. But how can we open file select dialog box on retry button click. Also is there a way to achieve file select dialog box using interop ?
Rajkiran SwainPosted May 31, 2023, 11:28 AM
When working with OpenXML to create Excel files, you cannot directly interact with the file system or user interface like you would with VBA. However, you can achieve a similar result by using Excel's built-in functionality and leveraging data validation.
Here's one approach you can follow:
Create a cell in Excel where the user can enter or select a file path. Let's say this cell is A1.
Apply data validation to the cell to restrict the input to a specific type, such as "Text Length" or "Custom Formula." In the case of a file path, you can use a custom formula to validate the input. For example, you can use a formula like
=AND(LEN(A1)>0, ISNUMBER(SEARCH("\", A1)))to ensure that the cell contains a non-empty value and that it includes a backslash character.Set the data validation error alert style to "Stop" and customize the error message to instruct the user to enter a valid file path.
When the user wants to select a file, they can double-click on the cell (A1 in this example) to activate the data validation. Excel will display an error message dialog with the custom message you set. The user can then click on the "Retry" button, which will open a file selection dialog box.
After the user selects a file, the file path will be populated in the cell (A1).
Keep in mind that this approach relies on Excel's functionality and the user's interaction with the file. The file selection dialog box is not triggered directly from OpenXML code but from the user's action within the Excel application.
By implementing this approach, you can capture file paths from within an Excel cell using OpenXML without directly interacting with the file system or using VBA.