Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello everyone, I want to know the reason for this error. I tried to fix it and failed. I want to open Word on the page. Thank you everyone. Is there a solution to this error?

What I have tried:

Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30002: Type 'Word.Application' is not defined.

Source Error:


Line 497:
Line 498:    Private Sub Button2_Click(sender As Object, e As System.EventArgs) Handles Button2.Click
Line 499:        Dim oWord As Word.Application
Line 500:        Dim oDoc As Word.Document
Line 501:        oWord = CreateObject("Word.Application")


VB
Private Sub Button2_Click(sender As Object, e As System.EventArgs) Handles Button2.Click
        Dim oWord As Word.Application
        Dim oDoc As Word.Document
        oWord = CreateObject("Word.Application")
        oWord.Visible = True
        oDoc = oWord.Documents.Add("C:\wordfile.docx")
    End Sub
Posted
Updated 25-Jan-24 5:16am
v2

The message is clear, the compiler cannot find a reference to the class or namespace Word in your source. Have you added a reference to Microsoft.Office.Interop.Word Namespace | Microsoft Learn[^], and included it?
 
Share this answer
 
Ummm... You CAN'T open Word on the page. The code you've written will open word on the web server, where nobody will see it, NOT on the client machine.

The reason the code is failing is because you don't have Office installed on your dev machine.
 
Share this answer
 
As others have pointed out, you can't open MS Word on your website. However, you do have some options:
1. You can embed Word Documents for viewing. Here is a Google search with many examples of how: embed ms word on your website - Google Search[^]
2. Use a 3rd-party Word-like editor. Syncfusion has one that works with multiple frameworks - Asp.Net Core, Asp.Net MVC, Blazor, Javascript, etc. here is the JS version: JavaScript Word Processor | WYSIWYG Document Editor | Syncfusion[^]. IT supports MS Word documents. This is a commercial library, however they have a Community Licence which is free: Free access to over 1,800 controls | Community License | Syncfusion[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900