Section 5.18.Distribute Excel .NET Documents


5.18. Distribute Excel .NET Documents

If you distribute an Excel workbook that uses .NET code to others who don't have Excel 2003, the .NET code is ignored and programmed features are unavailable. Earlier versions of Excel can open Excel 2003 workbooks, but they can't run .NET assemblies on start-up.


Note: If you distribute an Excel .NET document to an Excel 2003 user who doesn't have access to the assembly location, Excel displays an error message when that user opens the workbook.

Figure 5-23. Choose the policy level to deploy and enter a filename to create


If you want to distribute a Workbook to Excel 2003 users who don't have access to the .NET assembly, either distribute and install the assembly with the workbook as described in "Distribute Excel .NET Applications" or clear the _AssemblyName0 and _AssemblyLocation0 custom document properties before sending. For example, the following code saves a copy of the current document without the references to the .NET assembly; then sends the workbook via email:

    Private Sub cmdSend_Click(  ) Handles cmdSend.Click        Dim _AssemblyName0 As String, _AssemblyLocation0 As String, _          name As String         ' Save custom propeperty settings.        _AssemblyName0 = _          ThisWorkbook.CustomDocumentProperties("_AssemblyName0").Value        _AssemblyLocation0 = _          ThisWorkbook.CustomDocumentProperties("_AssemblyLocation0").Value        ' Clear custom property settings.        ThisWorkbook.CustomDocumentProperties("_AssemblyName0").Value = ""        ThisWorkbook.CustomDocumentProperties("_AssemblyLocation0").Value = ""        ' Save current name.        name = ThisWorkbook.FullName        ' Save a copy of the workbook (without properties).        ThisWorkbook.SaveAs("Copy of " & ThisWorkbook.Name)        ' Send the workbook.        ThisWorkbook.SendMail("ExcelDemo@hotmail.com", ThisWorkbook.Name)        ' Set properties and name back to original        ThisWorkbook.CustomDocumentProperties("_AssemblyName0").Value _           = _AssemblyName0        ThisWorkbook.CustomDocumentProperties("_AssemblyLocation0").Value = _          _AssemblyLocation0        ThisWorkbook.SaveAs(name)    End Sub

Once the _AssemblyName0 and _AssemblyLocation0 properties are cleared, the workbook no longer runs code from the .NET assembly so the workbook has reduced functionality.



    Excel 2003 Programming. A Developer's Notebook
    Excel 2003 Programming: A Developers Notebook (Developers Notebook)
    ISBN: 0596007671
    EAN: 2147483647
    Year: 2004
    Pages: 133
    Authors: Jeff Webb

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net