• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 940
  • Last Modified:

Process Word document in c++

Perhaps someone could assist in converting the following VB code to c++.


Dim app as Object

Public Function convertHtmlCopyResultsToClipboard(fileName As String) As Boolean
    Dim doc As Word.Document
    Dim stl As Word.Style
    Dim tbl As Word.Table
    If app Is Nothing Then
        Set app = CreateObject("Word.Application")
    End If
    app.Visible = False
    app.Documents.Open fileName ' this is an html file if that matters
    Set doc = app.ActiveDocument
    For Each tbl In doc.Tables


 End Function
1 Solution
Here are the steps (given for word 8 but you can update as necessary for your version of word)

- Import msword8.tlb (or a suitable type library for microsoft word) or if you are using MFC Use the class wizard and select "Add class from Type Library" and select msword8.tlb.

The following steps are for the later approach.

- Class wizard should've added new classes to your solution like _Application, _Document etc.

COleVariant var;
((LPVARIANT)var)->vt = VT_ERROR;

_Application application;
      // error
Documents documents = application.GetDocuments();

COleVariant varName,varFormat;
varName = filename;
_Document document = documents.Open(varName ,var, var, var, var, var, var, var, var, var);

Tables tables = document.GetTables();
for(int i=0; i<tables.GetCount(); i++)
     Table table = tables.GetItem(i);

and so on ...

Hope that helps!
joexAuthor Commented:
It helps, but there are all kinds of problems with interacting with desktop instances of word when a DLL is repeatedly used to modify html by removing its tables.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now