0

I cant really seem to find a documentation for word addins in C#. Like to find out how to insert text I played with intellisense for half and hour to find Application.Selection.Range.InsertAfter(); Is there a documentation to this I'm trying to figure out how to print out formatted text like a link but I'm finding little resources.

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Mark Lalor
  • 7,820
  • 18
  • 67
  • 106
  • Sad answer but: Google is your friend. I agree that documentation is poor and lacks examples. One advice I can give you (especially in .net4 where you get dynamics all over the place) is to make sure to cast everything to it's known type where possible otherwise intellisense is gone as well and that makes it even harder. Ultimately I think the underlying office object model is overly generalised over the years making it very unintuitive to use. – Eddy Aug 20 '11 at 00:55

2 Answers2

2

Your are not really specifying what you want to do exactly. One of the best starting points into figuring out how to do stuff in office automation is to record a macro and then look at what it generated.

For this question I entered a line of text in a document:

This is a new line of text and this a link

Then I used ctrl+leftarrow 3 times to move the cursor before 'this' and selected the next 4 chars (this). Then I turned the selection into a hyperlink pointing to stackoverflow This is resulting code:

Selection.TypeText Text:="This is a new line of text and this a link"
Selection.MoveLeft Unit:=wdWord, Count:=3
Selection.MoveRight Unit:=wdCharacter, Count:=4, Extend:=wdExtend
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _
    "http://www.stackoverflow.com/", SubAddress:="", ScreenTip:="", _
    TextToDisplay:="this"

In general it's not that hard to convert this vba stuff to c# and finding the proper methods

Eddy
  • 5,320
  • 24
  • 40
  • I just find it hard to find out this stuff without documentation... how did you learn that, searching though the object browser? – Mark Lalor Aug 20 '11 at 01:13
  • No by recording a macro and then looking at the recorded vba code (which is what I pasted here). It tells you what methods to use and from there you can google with more relevant terms – Eddy Aug 20 '11 at 01:19
  • That's really useful, I think there's even online converts from VB to C# but I understand the language anyways. Never did anything with macros but now I definitely will. – Mark Lalor Aug 20 '11 at 01:25