Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #9   Report Post  
Jonathan West
 
Posts: n/a
Default


"zalek" wrote in message
oups.com...
Jonathan,

I really appreciate your time - thanks for answering.

Let me bug you a little more.
I already order a few books on VBA, but meantime:
I have a .txt file with text and list of words I want to appear in the
Index, based on the text in my .txt file.

My question:

1. What is a field object?


Without bothering with VBA, open some document, go to the Insert menu,
select "Field..." and from the dialog that appears pick some field to insert
in the document. Press Alt-F9 to toggle between displaying field codes and
field results in the document. You now know what a field is.

Open the VBA editor, display the Immediate window. In the immediate window,
type "Print ActiveDocument.Fields.Count" and press Enter. Since you have
already entered a field in the document, the value which is printed should
be 1. if you have experimented with entering more fields in the document,
the value may be higher.


I made a test - created a word document with a few words and created a
macro:

Sub VBAtest1()
Dim oField As Field
Dim i As Integer
Open "c:\vab-test.txt" For Output As #1
i = ActiveDocument.Fields.Count
Write #1, i
Close #1

End Sub

File shows zero. So what is a Field in the document?


if you are opening a plain text file rather than a Word document, I am not
in the least bit surprised that there are no fields in it.


2. Let say in my document each field I want to index I'll write with
prefix @@, for example if I'll want to index the word "Zalek" - I will
write it as "@@Zalek".
What are VBA commands that will let me scan all words in the document
and test if they have prefix "@@"?


There are two parts of this. First you need a way to recognise every word
that starts with @@. And then you need to strip off the @@ and insert a
field after it.

For the first part, I suggest you take a look at the Find object. There are
lots of code samples in messages to this group dealing with the Find object.

Then you need to look at the Add method of the Fields collection in the VBA
help to work out how to add the field. Start out just by using the code
sample there, and just do a bit of experimenting. Also, record a macro while
inserting a field by hand isong the Insert Fields dialog, and see what the
code looks like. If you get stuck, post the code you have so far and
somebody will comment on it.

But I'm not going simply to write the code for you when you don't appear to
have looked up the references I have already given you.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

 
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating a table of contents Frank Drost Microsoft Word Help 1 July 8th 05 05:54 AM
Updating a table of contents Frank Drost Microsoft Word Help 9 June 29th 05 05:41 AM
developing multiple table of contents Chad Microsoft Word Help 1 June 22nd 05 04:40 AM
Table AutoFormats vs. Table Styles confusion Tony Jollans Tables 5 March 6th 05 07:18 PM
Item in Table of Contents throw off numbering Robert McN Page Layout 4 January 27th 05 12:50 AM


All times are GMT +1. The time now is 11:25 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"