Solved

Paragraph border persists across open and close of Word doc

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Outlook Free & Paid Tools
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

728 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