Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've not used any third-party tools before, as I've only ever written Office automation applications for PCs which already have Office installed.</p> <p>Creating documents from scratch, or basing them on a template, is quite straightforward. With templates, you can define bookmarks and mail-merge fields to make finding and replacing document elements easier.</p> <p>Here's a few things that you may find useful:</p> <p><strong>Named and Optional Arguments</strong><br> The Word object model is reasonably easy to work with. VB.NET used to be easier to work with than C#: as the Office automation APIs were originally written with VB in mind, you could take advantage of optional parameters. In earlier versions of C#, you had to specify every argument in API calls, which was quite tedious. I understand that this has changed in Visual C# 2010:</p> <p>How to: Use Named and Optional Arguments in Office Programming (C# Programming Guide) <a href="http://msdn.microsoft.com/en-us/library/dd264738.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/dd264738.aspx</a></p> <p><strong>Tutorials</strong><br> I found these tutorials quite handy:</p> <p>Automating Office Programs with VB.NET<br> <a href="http://www.xtremevbtalk.com/showthread.php?t=160433" rel="nofollow noreferrer">http://www.xtremevbtalk.com/showthread.php?t=160433</a></p> <p>VB.NET Office Automation FAQ<br> <a href="http://www.xtremevbtalk.com/showthread.php?t=160459" rel="nofollow noreferrer">http://www.xtremevbtalk.com/showthread.php?t=160459</a></p> <p>Understanding the Word Object Model from a .NET Developer's Perspective<br> <a href="http://msdn.microsoft.com/en-us/library/aa192495%28office.11%29.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/aa192495%28office.11%29.aspx</a></p> <p><strong>Early and Late binding</strong><br> One point worth mentioning: late-binding is normally recommended against, but it can be very useful if you don't know what version of Office will be deployed on the application's host. Early-binding tends to operate faster, and has the advantage of intellisense in your IDE:</p> <p>Using early binding and late binding in Automation<br> <a href="http://support.microsoft.com/kb/245115" rel="nofollow noreferrer">http://support.microsoft.com/kb/245115</a></p> <p>Early vs. Late Binding<br> <a href="http://word.mvps.org/faqs/interdev/earlyvslatebinding.htm" rel="nofollow noreferrer">http://word.mvps.org/faqs/interdev/earlyvslatebinding.htm</a></p> <p><strong>Search and Replace</strong><br> One thing to be aware of is that the <a href="http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.find.aspx" rel="nofollow noreferrer">find</a> and <a href="http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.replacement.aspx" rel="nofollow noreferrer">replacement</a> objects may not work as you would expect. Rather than searching the whole document, it searches just the main text. If you have text frames in the document, these will be ignored. Instead, you have to loop through all the StoryRanges, and search the content of each. Here's what I do in VB.NET to search the main text story and text frames:</p> <pre><code>Private Sub FindReplaceAll(ByVal objDoc As Object, ByVal strFind As String, ByVal strReplacement As String) Dim rngStory As Object For Each rngStory In objDoc.StoryRanges Do If rngStory.StoryType = wdMainTextStory Or rngStory.StoryType = wdTextFrameStory Then With rngStory.Find .Text = strFind .Replacement.Text = strReplacement .Wrap = wdFindContinue .Execute(Replace:=wdReplaceAll) End With End If rngStory = rngStory.NextStoryRange Loop Until rngStory Is Nothing Next rngStory End Sub </code></pre> <p>StoryRanges Collection Object<br> <a href="http://msdn.microsoft.com/en-us/library/bb178940%28office.12%29.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/bb178940%28office.12%29.aspx</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload