Solved

Paragraph border persists across open and close of Word doc

Posted on 2011-09-13
3
198 Views
Last Modified: 2012-08-13
My Access app opens and closes an associated docx regularly, adding some text every time.

CODE 1 shows that some text is input into a docx and a border put around the last item entered. It is then closed and saved.

CODE 2 shows that the docx is later opened and some text added. This text ends up in the borders left over last time.

How do I get rid of this?

Many thanks.
'
' CODE 1 - last things done before the docx is closed
'
    ' stick in log entry?
100   If InStr(mode, "L") Then
110     docapp.Selection.Font.size = 13
120     docapp.Selection.TypeText "Log for session: " & vbCrLf
        ' plant starting bookmark

130     docdoc.Bookmarks.Add "start", docapp.Selection.Range

        ' plant text from Access field
140     thislog = Forms![counselling log].[dealt with]      ' convert to string from access field
172     docapp.Selection.TypeText RegExpReplace(thislog, "<(.|\n)*?>") & vbCrLf & vbCrLf

        ' make a range from bookmark to where we are now
        'Set rng = docdoc.Range(docdoc.Bookmarks("start").Range.end, docapp.Selection.end)
150     Set rng = docdoc.Range(docdoc.Bookmarks("start").end, docapp.Selection.end)    ' create range to cover all text imported

        ' enable borders for all paras in this range
160     For Each par In rng.Paragraphs
170         par.Borders.Enable = True
180     Next par
190   End If

    ' stick in template?
200   If InStr(mode, "T") Then
210     temppath = DLookup("[session template path]", "[my details]")
220     If IsNull(temppath) Then
230         Call tellIt(Forms![session log]!Label193, Forms![session log], False)
240     Else
250         docapp.Selection.insertfile temppath
260     End If
270   End If

280   Set rng = Nothing
290   Set par = Nothing

300   docapp.ActiveDocument.SaveAs filename, , , password, , password
310   docapp.Application.Quit SaveChanges:=wdSaveChanges


320   Set docdoc = Nothing
330   Set docapp = Nothing

    'go home

Open in new window

'
' CODE 2 - first things done on re-opening the docx
'
    ' Does the file exist?
10        On Error GoTo Command118_Click_Error

    ' all OK, go do it...
    ' magic to get document, catch errors
20    Set docapp = CreateObject("Word.Application")

    ' then open the doc in the correct folder for the user
30    password = DLookup("[password readwrite]", "[my details]")
40    filename = Forms!switchboard!currentpath & "\cg4 docs\" & _
                                       Forms!switchboard!thisuser & "\" & Forms![counselling log].client_on_form & chDoc()
50    Set docdoc = docapp.Documents.Open(filename, , , , password, , , password)
60    On Error GoTo Command118_Click_Error

    ' goto end of doc and stick in new text
70    If DLookup("[no timestamp]", "[my details]") = False Then   ' timestamp otional...
80      docapp.Selection.EndKey Unit:=wdStory, Extend:=wdMove
    ' to end of text - wdStory = 6, wdMove = 0
90      docapp.Selection.Font.name = "Times New Roman"          ' format text
100     docapp.Selection.Font.Bold = False
110     docapp.Selection.Font.size = 11
120     docapp.Selection.TypeText vbCrLf & "___________________________" & vbCrLf   ' timestamp
130     docapp.Selection.TypeText "(Comment recorded on " & Format(Now, "MMMM dd, yyyy at hh:mm AM/PM") & ")"
140     docapp.Selection.TypeText vbCrLf & vbCrLf
150     docapp.Selection.Font.size = 13
160   End If

Open in new window

0
Comment
Question by:Peborgh
  • 2
3 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 36528543
Try inserting this line after line 21
docapp.ActiveDocument.Paragraphs.Last.Borders.Enable = False

Open in new window

0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 36528585
( - in your second snippet.)
0
 

Author Comment

by:Peborgh
ID: 36530103
That line of code after the file is opened worked a treat!

many thanks,

peter
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
Outlook Free & Paid Tools
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question