Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Thu, 28 Feb 2008 21:10:38 +0600,    group: microsoft.public.word.oleinterop        back       


Retrieval of fields   
Hello, NG

I use Word 2000 Interops for Word 2007 automation. Can't find proper way for 
retrieving fields from TextBoxes/TextFrames located in a Footer/Header of a 
document.

Enumeration through StoryRanges of a document won't help...

foreach (Range r in document.StoryRanges)
{
 foreach (Field f in r.Fields)
 {
  // fields in Footer/Header are hit

  //BUT
  //fields in TextBoxes/TextFrames located in Footer/Header are NOT hit
 }
}

Do not know whether it matters, but I found that my DOCX has two header*.xml 
files in its package.
Moreover, my fields which I look for are stored in header2.xml. May be 
header2.xml is not PRIMARY header, but
Word has only wdPrimaryHeaderStory story type. So second header is not in 
any story. Wild guess, but who knows... :)

Please help me find right direction.
TIA
Ivan
date: Thu, 28 Feb 2008 21:10:38 +0600   author:   Ivan A. Vasilyev

Re: Retrieval of fields   
Hi Ivan,

In simple terms, you can access all fields in a document via the StoryRanges collection. For example:

Sub ProcessFields()
Dim oRange As Range, oFld As Field
If ActiveDocument.Fields.Count > 0 Then
  For Each oRange In ActiveDocument.StoryRanges
    Do
      For Each oFld In oRange.Fields
 ' Do stuff
      Next oFld
    Loop Until oRange Is Nothing
 Next
End If
End Sub

StoryRange constants include:
wdCommentsStory, wdEndnotesStory, wdEvenPagesFooterStory, wdEvenPagesHeaderStory, wdFirstPageFooterStory, wdFirstPageHeaderStory, 
wdFootnotesStory, wdMainTextStory, wdPrimaryFooterStory, wdPrimaryHeaderStory, and wdTextFrameStory.

Since you apparently already know how to access the Header & Footer area, all you need to do to retrieve fields from 
TextBoxes/TextFrames located there is to add a test for any associated wdTextFrameStory objects.

Cheers
-- 
macropod
[MVP - Microsoft Word]
-------------------------

"Ivan A. Vasilyev"  wrote in message news:OLAGVwheIHA.4056@TK2MSFTNGP06.phx.gbl...
> Hello, NG
>
> I use Word 2000 Interops for Word 2007 automation. Can't find proper way for retrieving fields from TextBoxes/TextFrames located 
> in a Footer/Header of a document.
>
> Enumeration through StoryRanges of a document won't help...
>
> foreach (Range r in document.StoryRanges)
> {
> foreach (Field f in r.Fields)
> {
>  // fields in Footer/Header are hit
>
>  //BUT
>  //fields in TextBoxes/TextFrames located in Footer/Header are NOT hit
> }
> }
>
> Do not know whether it matters, but I found that my DOCX has two header*.xml files in its package.
> Moreover, my fields which I look for are stored in header2.xml. May be header2.xml is not PRIMARY header, but
> Word has only wdPrimaryHeaderStory story type. So second header is not in any story. Wild guess, but who knows... :)
>
> Please help me find right direction.
> TIA
> Ivan
>
date: Fri, 29 Feb 2008 10:45:49 +1100   author:   macropod lid

Re: Retrieval of fields   
Hello.

> In simple terms, you can access all fields in a document via the 
> StoryRanges collection. For example:
>
> Sub ProcessFields()
> Dim oRange As Range, oFld As Field
> If ActiveDocument.Fields.Count > 0 Then
>  For Each oRange In ActiveDocument.StoryRanges
>    Do
>      For Each oFld In oRange.Fields
> ' Do stuff
>      Next oFld
>    Loop Until oRange Is Nothing
> Next
> End If
> End Sub

It's not clear for me what "If ActiveDocument.Fields.Count > 0" condition is 
used for. AFAIK, ActiveDocument.Fields returns fields from MainStory only. 
"Do ... Loop Until oRange Is Nothing" is infinite loop I guess. Not quite 
sure of a role of the loop at all. But main idea is clear.

> StoryRange constants include:
> wdCommentsStory, wdEndnotesStory, wdEvenPagesFooterStory, 
> wdEvenPagesHeaderStory, wdFirstPageFooterStory, wdFirstPageHeaderStory, 
> wdFootnotesStory, wdMainTextStory, wdPrimaryFooterStory, 
> wdPrimaryHeaderStory, and wdTextFrameStory.
>
> Since you apparently already know how to access the Header & Footer area, 
> all you need to do to retrieve fields from TextBoxes/TextFrames located 
> there is to add a test for any associated wdTextFrameStory objects.

Could you give an example, please. Do not know how to get textboxes 
ASSOCIATED with particulare header/footer.

[PSEUDOCODE] document.StoryRanges.Item(wdTextFrameStory)

I guess, this is not the case, cause it does not work for me. I.e. it does 
not return textbox located in header.

TIA
Ivan.
date: Fri, 29 Feb 2008 13:30:54 +0600   author:   Ivan A. Vasilyev

Re: Retrieval of fields   
I've just narrowed down the problem to the following.
My Stories enumeration code does not hit fields in TextBoxes (only) located 
in header/footer.

the code is

foreach (Range r in document.StoryRanges)
{
 foreach (Field f in r.Fields)
 {
  // fields in Footer/Header are hit

  //BUT
  //fields in TextBoxes located in Footer/Header are NOT hit
 }
}

Is it possible to get all TextBoxes in a document? If true, i could search 
for fields there.

TIA
Ivan
date: Fri, 29 Feb 2008 14:29:50 +0600   author:   Ivan A. Vasilyev

Re: Retrieval of fields   
Take a look at the article "Using a macro to replace text where ever it 
appears in a document including Headers, Footers, Textboxes, etc." at:

http://www.word.mvps.org/FAQs/MacrosVBA/FindReplaceAllWithVBA.htm

You may be running up against the situation where your code is only acting 
upon the first story of each story type in the document.  There is code in 
that article that gets around that situation.
-- 
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Ivan A. Vasilyev"  wrote in message 
news:uwi2B1qeIHA.4476@TK2MSFTNGP06.phx.gbl...
> I've just narrowed down the problem to the following.
> My Stories enumeration code does not hit fields in TextBoxes (only) 
> located in header/footer.
>
> the code is
>
> foreach (Range r in document.StoryRanges)
> {
> foreach (Field f in r.Fields)
> {
>  // fields in Footer/Header are hit
>
>  //BUT
>  //fields in TextBoxes located in Footer/Header are NOT hit
> }
> }
>
> Is it possible to get all TextBoxes in a document? If true, i could search 
> for fields there.
>
> TIA
> Ivan
>
date: Fri, 29 Feb 2008 20:50:39 +1000   author:   Doug Robbins - Word MVP

Re: Retrieval of fields   
Hello, Doug.

Thanks for the link. Looping through stories of the same type 
(.NextStoryRange) did the trick, but with one EXCEPTION.
I managed to find all textboxes and fields located in that textboxes 
(through Shapes enumeration). But TextBoxes (Shapes) placed on CANVAS are 
still not hit.

Is it possible to pull shapes placed on a canvas?

TIA
Ivan

"Doug Robbins - Word MVP"  ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × 
ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ: news:%23%23jzwDseIHA.1212@TK2MSFTNGP05.phx.gbl...
> Take a look at the article "Using a macro to replace text where ever it 
> appears in a document including Headers, Footers, Textboxes, etc." at:
>
> http://www.word.mvps.org/FAQs/MacrosVBA/FindReplaceAllWithVBA.htm
>
> You may be running up against the situation where your code is only acting 
> upon the first story of each story type in the document.  There is code in 
> that article that gets around that situation.
> -- 
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP
>
> "Ivan A. Vasilyev"  wrote in message 
> news:uwi2B1qeIHA.4476@TK2MSFTNGP06.phx.gbl...
>> I've just narrowed down the problem to the following.
>> My Stories enumeration code does not hit fields in TextBoxes (only) 
>> located in header/footer.
>>
>> the code is
>>
>> foreach (Range r in document.StoryRanges)
>> {
>> foreach (Field f in r.Fields)
>> {
>>  // fields in Footer/Header are hit
>>
>>  //BUT
>>  //fields in TextBoxes located in Footer/Header are NOT hit
>> }
>> }
>>
>> Is it possible to get all TextBoxes in a document? If true, i could 
>> search for fields there.
>>
>> TIA
>> Ivan
>>
>
>
date: Fri, 29 Feb 2008 18:17:03 +0600   author:   Ivan A. Vasilyev

Re: Retrieval of fields   
Hi Ivan,

I don't know the answer to that - I turned off the Drawing Canvas the first 
time I saw it.  And, one of the problems with a number of the features that 
have been added to more recent versions of work is that they have not be 
made accessible through the Object model.

As this is not a very heavily trafficed newsgroup, I would suggest that you 
start a new thread in the microsoft.public.word.vba.general newsgroup, where 
it will get a wider audience and may be seen by someone who has already 
worked out how to do it.

-- 
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Ivan A. Vasilyev"  wrote in message 
news:evxy$zseIHA.536@TK2MSFTNGP06.phx.gbl...
> Hello, Doug.
>
> Thanks for the link. Looping through stories of the same type 
> (.NextStoryRange) did the trick, but with one EXCEPTION.
> I managed to find all textboxes and fields located in that textboxes 
> (through Shapes enumeration). But TextBoxes (Shapes) placed on CANVAS are 
> still not hit.
>
> Is it possible to pull shapes placed on a canvas?
>
> TIA
> Ivan
>
> "Doug Robbins - Word MVP"  ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × 
> ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ: news:%23%23jzwDseIHA.1212@TK2MSFTNGP05.phx.gbl...
>> Take a look at the article "Using a macro to replace text where ever it 
>> appears in a document including Headers, Footers, Textboxes, etc." at:
>>
>> http://www.word.mvps.org/FAQs/MacrosVBA/FindReplaceAllWithVBA.htm
>>
>> You may be running up against the situation where your code is only 
>> acting upon the first story of each story type in the document.  There is 
>> code in that article that gets around that situation.
>> -- 
>> Hope this helps.
>>
>> Please reply to the newsgroup unless you wish to avail yourself of my
>> services on a paid consulting basis.
>>
>> Doug Robbins - Word MVP
>>
>> "Ivan A. Vasilyev"  wrote in message 
>> news:uwi2B1qeIHA.4476@TK2MSFTNGP06.phx.gbl...
>>> I've just narrowed down the problem to the following.
>>> My Stories enumeration code does not hit fields in TextBoxes (only) 
>>> located in header/footer.
>>>
>>> the code is
>>>
>>> foreach (Range r in document.StoryRanges)
>>> {
>>> foreach (Field f in r.Fields)
>>> {
>>>  // fields in Footer/Header are hit
>>>
>>>  //BUT
>>>  //fields in TextBoxes located in Footer/Header are NOT hit
>>> }
>>> }
>>>
>>> Is it possible to get all TextBoxes in a document? If true, i could 
>>> search for fields there.
>>>
>>> TIA
>>> Ivan
>>>
>>
>>
>
>
date: Sun, 2 Mar 2008 10:25:16 +1000   author:   Doug Robbins - Word MVP

Re: Retrieval of fields   
Thank you, Doug.

"Doug Robbins - Word MVP"  ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × 
ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ: news:%23n1Bqv$eIHA.5208@TK2MSFTNGP04.phx.gbl...
> Hi Ivan,
>
> I don't know the answer to that - I turned off the Drawing Canvas the 
> first time I saw it.  And, one of the problems with a number of the 
> features that have been added to more recent versions of work is that they 
> have not be made accessible through the Object model.
>
> As this is not a very heavily trafficed newsgroup, I would suggest that 
> you start a new thread in the microsoft.public.word.vba.general newsgroup, 
> where it will get a wider audience and may be seen by someone who has 
> already worked out how to do it.
>
> -- 
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP
>
> "Ivan A. Vasilyev"  wrote in message 
> news:evxy$zseIHA.536@TK2MSFTNGP06.phx.gbl...
>> Hello, Doug.
>>
>> Thanks for the link. Looping through stories of the same type 
>> (.NextStoryRange) did the trick, but with one EXCEPTION.
>> I managed to find all textboxes and fields located in that textboxes 
>> (through Shapes enumeration). But TextBoxes (Shapes) placed on CANVAS are 
>> still not hit.
>>
>> Is it possible to pull shapes placed on a canvas?
>>
>> TIA
>> Ivan
>>
>> "Doug Robbins - Word MVP"  ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × 
>> ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ: news:%23%23jzwDseIHA.1212@TK2MSFTNGP05.phx.gbl...
>>> Take a look at the article "Using a macro to replace text where ever it 
>>> appears in a document including Headers, Footers, Textboxes, etc." at:
>>>
>>> http://www.word.mvps.org/FAQs/MacrosVBA/FindReplaceAllWithVBA.htm
>>>
>>> You may be running up against the situation where your code is only 
>>> acting upon the first story of each story type in the document.  There 
>>> is code in that article that gets around that situation.
>>> -- 
>>> Hope this helps.
>>>
>>> Please reply to the newsgroup unless you wish to avail yourself of my
>>> services on a paid consulting basis.
>>>
>>> Doug Robbins - Word MVP
>>>
>>> "Ivan A. Vasilyev"  wrote in message 
>>> news:uwi2B1qeIHA.4476@TK2MSFTNGP06.phx.gbl...
>>>> I've just narrowed down the problem to the following.
>>>> My Stories enumeration code does not hit fields in TextBoxes (only) 
>>>> located in header/footer.
>>>>
>>>> the code is
>>>>
>>>> foreach (Range r in document.StoryRanges)
>>>> {
>>>> foreach (Field f in r.Fields)
>>>> {
>>>>  // fields in Footer/Header are hit
>>>>
>>>>  //BUT
>>>>  //fields in TextBoxes located in Footer/Header are NOT hit
>>>> }
>>>> }
>>>>
>>>> Is it possible to get all TextBoxes in a document? If true, i could 
>>>> search for fields there.
>>>>
>>>> TIA
>>>> Ivan
>>>>
>>>
>>>
>>
>>
>
>
date: Mon, 3 Mar 2008 18:47:48 +0600   author:   Ivan A. Vasilyev

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us