Thread: [Solved] Append to Existing file
View Single Post
 
Old 07-29-2015, 11:18 AM
charlesdh charlesdh is offline Windows 7 32bit Office 2010 32bit
Expert
 
Join Date: Apr 2014
Location: Mississippi
Posts: 382
charlesdh is on a distinguished road
Default

Hi,

In the code below I'm attempting to append data from existing bookmarks.
When I run the code I can see the data in each bookmark. But, when I use the bookmark info it does not populate the existing file "log.txt".
But, when I assign the the data it will populate the file "log.txt".

Can someone tell me what I'm doing wrong?

Code:
Sub Test_BookMark_Append()
Dim filenr As Long
Dim Fname As Variant
Dim Lname As Variant
Dim Mage As String
Dim mypath
filenr = FreeFile
'Fname = ThisDocument.Bookmarks("FirstName").Range.Text' not working
'Lname = ThisDocument.Bookmarks("LastName").Range.Text' not working
'Mage = ThisDocument.Bookmarks("Mage").Range.Text' not working
Lname = "Sam"'''' works
Fname = "Dootie"'''' works
Mage = "70"'''' works
mypath = ThisDocument.Path & "\log.txt"
Open mypath For Append As #filenr
Print #filenr, Fname & "," & Lname & "," & Mage
Close #filenr
End Sub
Opp's I posted this at

http://www.mrexcel.com/forum/excel-q...-document.html

And

http://forums.techguy.org/business-a...ting-file.html

Sorry!

When using the bookmarks for some reason when appending to existing file creates a new row. How can I stop it?
Reply With Quote