Zz sends parameters to VSTO plug-ins and documents

Source: Internet
Author: User
This question has been seen on the Office Development Forum in Chinese and English MSDN (and I have provided the answer). It seems to be an "international demand. Record and share with you today.

The story is as follows: a developer has a WinForm application that reads a record from the database and obtains a record ID. Then, you need to open Word or Excel, use the prepared VSTO document or plug-in to generate the corresponding Office document content based on the Record ID. The question is, how can I pass this ID to Word or Excel?

There is a very simple implementation method-directly add parameters in the command line that starts Word/Excel! For example:

<Excel.exe>/r "D: \ ExcelWorkbook1.xlsx"/e/id: 1234

<Excel.exe> is the complete path of Excel.exe.

/R is followed by the complete path of the VSTO Excel document.

/E tells Excel not to open a blank new document.

/Id: 1234 is the custom parameter. You can input your id number here. Of course, the parameter name can also be other, not necessarily "id ".

Step 2: In the VSTO Excel document, you can use the following code to enumerate command line parameters:

For Each a As String In Environment. GetCommandLineArgs
MsgBox ()
Next

If the code above is executed, all command line parameters are displayed.

You only need to find the parameter starting with/id: and retrieve the number.

You can also use a similar method for Word, except that parameters such as/r/e must be replaced with corresponding Word parameters.

This method is applicable to Word 2007/Excel 2007, but I cannot guarantee whether it can be used in future versions. Especially if the custom parameters you added are accidentally used as standard parameter names by the new version ...... So it is better to have a unique parameter name.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.