I suggest you should post to: microsoft.public.word.vba.general
[quoted text, click to view] "craig" <craig@discussions.microsoft.com> wrote in message
news:40DD8E55-A891-4FF5-BB4C-66BE2795F6CF@microsoft.com...
>I am trying to insert text into a Word document and then apply a style to
>the
> paragraph I just wrote. My problem is that the range stays set to the
> entire
> document and I can't figure out how to reset it to the end of the document
> so
> whatever style I apply applies to just the last paragraph I wrote. Right
> now
> the style gets applied to the entire document. Here is the class:
>
> Imports System.IO
> Imports System.Runtime.InteropServices
> Imports Microsoft.Office.Interop.Word
> Imports Microsoft.Office.Interop.PowerPoint
>
> Public Class CR_Document_Writer
> Private _Word As New Microsoft.Office.Interop.Word.Application
> Private _doc As Microsoft.Office.Interop.Word.Document
> Public Sub Create()
> Try
> _doc = _Word.Documents.Add("Test.dot")
> _doc.Activate()
> _Word.Visible = True
> Append("Title Of The Document", "Title")
> Append("This is a line of text.", "List Bullet")
> _doc.SaveAs("c:\test.doc")
> Catch ex As COMException
> MessageBox.Show("Error accessing Word document.")
> End Try
> End Sub
> Private Sub Append(ByVal TextString As String, ByVal inStyle As String)
> Try
> _doc.Range.Collapse(WdCollapseDirection.wdCollapseEnd)
> _doc.Range.InsertAfter(TextString)
> _doc.Range.Style = inStyle
> _doc.Range.InsertParagraphAfter()
> Catch ex As Exception
> MessageBox.Show("Error in writing to Word document.")
> End Try
> End Sub
> End Class
>
> What am I doing wrong?
>
> Thanks,
> Craig