Solved

Paragraph border persists across open and close of Word doc

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
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…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

747 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

13 Experts available now in Live!

Get 1:1 Help Now