Access MVP (2010-2015)

oOo.oOo.oOo.oOo.oOo.oOo

Delete a line from exported .RTF document…

Recently, I exported an Access Report  to Word (.RTF).  Nope, did not use Albert’s Super Easy Word Merge because the nature of the report with its many Subreports and Sub-Subreports did not lend itself to a mail merge.  Only after I exported it I needed to first copy it in its entirety to another document and then remove a line from the original document.

Function strDeleteLine(strPath As String)
'http://www.access-diva.com/tips.html
      Dim objWord As Object
      Dim objDoc As Object
      Dim objSelection As Object

      Set objWord = CreateObject("Word.Application")
      Set objDoc = objWord.Documents.Open(strPath)

      objDoc.Range.Select
      objWord.Selection.Find.Text = "Beginning text of the line you want to delete"

      Do While objWord.Selection.Find.Execute(FindText:="Beginning text of the line you want to delete", Forward:=True, Format:=True) = True
         With objWord.Selection
           'wdLine = 5
           .Expand Unit:=5
           .Delete
         End With
      Loop
End Function

 836 total views,  2 views today

Comments are closed.