Get certain words from a line into a cell

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

Hello

Just hoping someone can send me in the right direction here with a
method that might work here. I am extracting data from text files
based on finding a certain word. If found, the whole line in the text
doc will be pasted into a row in excel. There are certain things in
these rows like just the web address, or page title, that I want in
the Excel doc rather than the entire line. Would this be parsing
usign tokens or something? Any help or pointers would be great!
Thanks a lot

Mark
 
Hello

Just hoping someone can send me in the right direction here with a
method that might work here. I am extracting data from text files
based on finding a certain word. If found, the whole line in the text
doc will be pasted into a row in excel. There are certain things in
these rows like just the web address, or page title, that I want in
the Excel doc rather than the entire line. Would this be parsing
usign tokens or something? Any help or pointers would be great!
Thanks a lot

Mark

Try with something like this:

Sub GetTitle()
Dim sLine As String, iStart As Integer, iEnd As Integer, cTitle As
String

sLine = "<head id=ctl00_ctl00_Head1><base href=http://
www.sqlteam.com/default.aspx /><meta http-equiv=Content-Type
content=text/html; charset=utf-8 /><link rel=SHORTCUT ICON href=http://
www.sqlteam.com/favicon.ico /><link rel=alternate type=application/rss
+xml title=SQLTeam.com -- SQL Server Information href=http://
feeds.sqlteam.com/sqlteam /><title>Generating ADO Parameters with
Information Schema Views - SQLTeam.com</title><link rel=stylesheet
href=sqlteam2.css type=text/css /><link rel=stylesheet href=csharp.css
type=text/css />"

iStart = InStr(1, sLine, "<title>", vbBinaryCompare) +
Len("<Title>")
iEnd = InStr(1, sLine, "</title>", vbBinaryCompare)

cTitle = Mid(sLine, iStart, iEnd - iStart)
MsgBox cTitle, , "Title"

End Sub

This extracts the page title, something similar can be done to extract
the url.

notice that the line used is not a valid html text, all double quotes
have been removed to show the example.

source of example: http://www.sqlteam.com/article/generating-ado-parameters-with-information-schema-views


HTH

Jaime Vasquez
 
It is kind of hard to give you code without more information. Can you show
us a (real) sample of text from the text file and the words you would be
looking for and the parts you want extracted?

Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top