Thread: [Solved] Append to Existing file
View Single Post
 
Old 07-30-2015, 03:15 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,512
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The problem is that you have bookmarked entire cells, including the end-of-cell markers, that get included in the output. You need to exclude those. Try:
Code:
Sub Test_BookMark_Append()
Dim filenr As Long
Dim Ffname As String
Dim Llname As String
Dim BD As String
Dim Adrs As String
Dim mypath
Dim Rng As Range
filenr = FreeFile
With ThisDocument
  Set Rng = .Bookmarks("FName").Range
  With Rng
    .End = .End - 1
    Ffname = .Text
  End With
  Set Rng = .Bookmarks("LName").Range
  With Rng
    .End = .End - 1
    Llname = .Text
  End With
  Set Rng = .Bookmarks("BirthDate").Range
  With Rng
    .End = .End - 1
    BD = .Text
  End With
  Set Rng = .Bookmarks("StreetAddress").Range
  With Rng
    .End = .End - 1
    Adrs = .Text
  End With
End With
'Lname = "Sam" '''' works
'Fname = "Dootie" '''' works
'BD = "70" '''' works
'Adrs = "1234 Myroad" ''''works
mypath = ThisDocument.Path & "\log.txt"
Open mypath For Append As #filenr
Print #filenr, Ffname & "," & Llname & "," & BD & "," & Adrs
Close #filenr
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote