Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2004

Tip: Looking for answers? Try searching our database.

VBA search for text string in non-Word doc?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ed - 02 Nov 2004 15:11 GMT
I am using TextStream to create documents.  I also need to grab several text
strings from the documents.  At the moment, I create and save the doc with
TextStream, then reopen it with Word and do my searches.  This adds a
monumental amount of time to running this program.  Is it possible to search
it with Word VBA as a non-Word document as it's created and while it's still
open?

Code to create doc:
Set docTIR = fs.CreateTextFile(strNewDoc)
docTIR.Write (strNewTIR)
docTIR.Close

Ed
Jay Freedman - 02 Nov 2004 16:19 GMT
> I am using TextStream to create documents.  I also need to grab
> several text strings from the documents.  At the moment, I create and
[quoted text clipped - 9 lines]
>
> Ed

Hi Ed,

You don't say where you're getting the content of strNewTIR that you're
writing into the file, but you should be able to use the InStr function on
strNewTIR to find substrings. Can you describe more explicitly what you're
trying to do?

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

Ed - 02 Nov 2004 17:31 GMT
Thanks for replying, Jay.  Sorry I wasn't more specific - I should know by
now!

Right now, I'm scanning through each created document for certain text
strings as "labels" for information to populate an Excel file as a document
index.  For instance, I will search each doc for "3.  TITLE: "; when found,
the range can then be collapsed and reset either left or right to encompass
the doc title, which is captured as a string and written to the Excel file.

It works, but only if I close each TextStream doc and reopen as a Word
doc, search, and close.  That eats up a lot of time, and I'd like to make it
faster.  I do hundreds, often thousands, of docs like this.

Ed

> > I am using TextStream to create documents.  I also need to grab
> > several text strings from the documents.  At the moment, I create and
[quoted text clipped - 16 lines]
> strNewTIR to find substrings. Can you describe more explicitly what you're
> trying to do?
Helmut Weber - 02 Nov 2004 19:27 GMT
Hi Ed,
as far as I understand this, you don't process word files
at all, but text-files. All you need is to make use of the string
functions availabe in any programming language. You got
delimiters, such as chr(13), which split the text-string up
into discrete parts. If such a part contains "3.  TITLE: ",
then you may put that part into a database or an Excel-Sheet,
or process it further beforehand. I think you have to read
character by character, store what's coming in into a string,
until a delimiter is found, process the result, and do with it
whatever you like, depending on the processing.
Certainly easier said than done.
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
Ed - 02 Nov 2004 19:33 GMT
Hi, Helmut.  The process actually involves taking a very long text file,
finding a certain portion and saving it to a string, then opening a new
file and writing the string to it.  From this, I need to extract some
internal
text as strings to populate and Excel file which is used as an index.  I'm
trying to get around closing and reopening the file.

Ed

> Hi Ed,
> as far as I understand this, you don't process word files
[quoted text clipped - 14 lines]
> Word XP, Win 98
> http://word.mvps.org/
Helmut Weber - 03 Nov 2004 11:07 GMT
Hi Ed,
in principle it could work like this:
Public Sub Test601()
Dim sInp As String
Dim sTmp As String
Open "c:\test\textfile.txt" For Input As #1
'---
While Not EOF(1)
  sInp = Input(1, #1) ' 1 character
  If sInp <> Chr(13) Then
     sTmp = sTmp & sInp
  Else
     If InStr(sTmp, ".  TITLE: ") Then
        MsgBox "got you : " & sTmp ' !!!
     End If
     sTmp = ""
  End If
Wend
'---
Close #1
End Sub
But a lot depends on the structure of the textfile.
It could be, theoretically, that there is no chr(13)
in it. Or no other character other than a-z, 0-9 etc.
Then it would not have a structure at all, or at
least a structure, that would be difficult to accesss.
If the file is structured by lines, then you may
read line by line and not character by character,
as I did here, which is by far the slowest way.
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.