Solved

Paragraph border persists across open and close of Word doc

Posted on 2011-09-13
3
195 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now