Word and User Forms

Add-in Express™ Support Service
That's what is more important than anything else

Word and User Forms
Manipulating Word from Windows Form 
James Thomas




Posts: 5
Joined: 2015-09-11
Hi Guys,

Great piece of software. I'm new at using ADX and hopefully this will be relatively easy to assist with...

When using an ADXWordTaskPane I can read / write / manipulate Word using a combination of Word. and WordAppObj.

For example:

Dim rng As Word.Range
rng = WordAppObj.ActiveDocument.content
with rng.find
.text = "Find something"
.execute()
end with


However, when i'm adding a Windows Form to my project I can't seem to access "WordAppObj".

What im trying to do is enumerate the styles used in the current word document and list them in a combo box contained on the form. I want to be able to manipulate the styles from the form. I don't want to have to use the ADXWordTaskPane if possible.

I've tried using the example from the website-

Dim curDoc As Word.Document
curDoc = WordApp.ActiveDocument

Dim i As Integer

'Change all styles to use my favorite font :-)
For i = 1 To curDoc.Styles.Count
With curDoc.Styles.Item(i)
.Font.Name = "Comic Sans MS"
End With
Next

Marshal.ReleaseComObject(curDoc)


This gives me an error saying


'WordApp' is not declared. It may be inaccessible due to its protection level


Any advice on what i'm missing is greatly appreciated - I'm using vb.net.

Thanks

JT
Posted 11 Sep, 2015 19:25:04 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello James,

WordAppObj is a property part declared on ADXWordTaskPane. Note that it is declared as Object; I would cast it to Word.Application before using it.

Another approach would be to use the WordApp property declared on the add-on module. You use it in this way: {add-in project name e.g. MyAddin1}.AddinModule.CurrentInstance.WordApp.{property or method}. This approach can be used in any class of your add-in, including the form.


Andrei Smolin
Add-in Express Team Leader
Posted 14 Sep, 2015 06:13:20 Top