?
Solved

Paragraph border persists across open and close of Word doc

Posted on 2011-09-13
3
Medium Priority
?
203 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

771 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