ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Manipulating text file data (https://www.excelbanter.com/excel-programming/354201-manipulating-text-file-data.html)

Kingdbag

Manipulating text file data
 

Hi guys,

I have a text file that I am working with that i would like to append
data to sort of.

</Placemark
new information
</Document
</Folder
</kml

I would like to open the file move up between </Placemark and
</Document and add some new data. I' having a hard time finding any
info other than normal inputs or appends anyone have an idea? I'm sure
its simple but im having a major block today, and its driving me nuts!
All using VBA of course I need to get info from a dialog and write it
to text not to a spreadsheet.


--
Kingdbag
------------------------------------------------------------------------
Kingdbag's Profile: http://www.excelforum.com/member.php...o&userid=17900
View this thread: http://www.excelforum.com/showthread...hreadid=515914


Charlie

Manipulating text file data
 
As long as "</Placemark" occurs only once in the input file, and the new
information is simply one string, you could try something like

Dim NewInformation As String

NewInformation = "Whatever"

Open "Your Input File" For Binary As #1
Open "Your Output File" For Binary As #2

Put #2, 1, Replace(Input(LOF(1), #1), "</Placemark", _
"</Placemark" & NewInformation)

Close #1
Close #2


"Kingdbag" wrote:


Hi guys,

I have a text file that I am working with that i would like to append
data to sort of.

</Placemark
new information
</Document
</Folder
</kml

I would like to open the file move up between </Placemark and
</Document and add some new data. I' having a hard time finding any
info other than normal inputs or appends anyone have an idea? I'm sure
its simple but im having a major block today, and its driving me nuts!
All using VBA of course I need to get info from a dialog and write it
to text not to a spreadsheet.


--
Kingdbag
------------------------------------------------------------------------
Kingdbag's Profile: http://www.excelforum.com/member.php...o&userid=17900
View this thread: http://www.excelforum.com/showthread...hreadid=515914



Kingdbag[_2_]

Manipulating text file data
 

I had to modify it a tiny bit but it did what i was looking for thanks a
ton I couldn't think of how to do it or find it on google for some
reason.

Dim NewInformation As String

NewInformation = "test"

Open "my file" _
For Binary As #1
Open "my file" _
For Binary As #2

Put #2, 1, Replace(Input(LOF(1), #1), "</Document", _
NewInformation & vbCrLf & "</Document")

Close #1
Close #2


--
Kingdbag
------------------------------------------------------------------------
Kingdbag's Profile: http://www.excelforum.com/member.php...o&userid=17900
View this thread: http://www.excelforum.com/showthread...hreadid=515914


Charlie

Manipulating text file data
 
Now you got it! I thought about the vbCrLf after I posted. Glad to help.

"Kingdbag" wrote:


I had to modify it a tiny bit but it did what i was looking for thanks a
ton I couldn't think of how to do it or find it on google for some
reason.

Dim NewInformation As String

NewInformation = "test"

Open "my file" _
For Binary As #1
Open "my file" _
For Binary As #2

Put #2, 1, Replace(Input(LOF(1), #1), "</Document", _
NewInformation & vbCrLf & "</Document")

Close #1
Close #2


--
Kingdbag
------------------------------------------------------------------------
Kingdbag's Profile: http://www.excelforum.com/member.php...o&userid=17900
View this thread: http://www.excelforum.com/showthread...hreadid=515914




All times are GMT +1. The time now is 07:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com