From: Bear on 17 Mar 2010 17:09 Does anyone know how to fix this behavior? I have a custom form for cross-references. This uses the GetCrossReferenceItems method of the active document to fill a variant array. I then unpack the array into my form list box. In some sessions, the lists fill only partially -- because the array is only filled partly. For example, I may have ten chapters, but the method only seems to return two x-refs. However, if I step through this code it works perfectly. It almost seems like a timing issue. I added a DoEvents before I execute method, and that seemed to help for awhile, but now it's misbehaving again. Any ideas? -- Windows XP, Word 2003
From: Doug Robbins - Word MVP on 17 Mar 2010 17:20 You have not even shown us the haystack in which you would like us to find the needle. -- 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, originally posted via msnews.microsoft.com "Bear" <david.chinell(a)ge.com(nospam)> wrote in message news:15FDB348-C783-4860-AA5F-70FE9372E38C(a)microsoft.com... > Does anyone know how to fix this behavior? I have a custom form for > cross-references. This uses the GetCrossReferenceItems method of the > active > document to fill a variant array. I then unpack the array into my form > list > box. > > In some sessions, the lists fill only partially -- because the array is > only > filled partly. For example, I may have ten chapters, but the method only > seems to return two x-refs. However, if I step through this code it works > perfectly. It almost seems like a timing issue. > > I added a DoEvents before I execute method, and that seemed to help for > awhile, but now it's misbehaving again. > > Any ideas? > -- > Windows XP, Word 2003
From: Bear on 17 Mar 2010 19:08 Doug: I hope by that you meant you wanted to see the code. It's in a custom userform. Here it is. When I hit this sub, I've already loaded the varRefType with the type I've selected by clicking an option button. This works perfectlly when I step through it after clicking to select "Chapter". I get ten items in the list. But when I run it I only get two items in the list. I've used debug.print to determine that the ubound of varXRefs is 10 when I step it, and 2 when I run it. I don't think it's a code problem, because it works perfectly with Word 2000, but not Word 2003. After I put the DoEvents statement in about six months ago, it worked for Word 2003 as well. But now it's stopped working. I'm looking for a known issue where the method is sometimes flakey, and for a workaround. (Declarations) Dim varXRefs As Variant Sub UpdateItemList() ' Use varRefType to fill the Item list accordingly Me.lstItem.Clear ' Prevent a partial or empty Item list in Word 2003 DoEvents varXRefs = ActiveDocument.GetCrossReferenceItems _ (ReferenceType:=varRefType) For Index = 1 To UBound(varXRefs) Me.lstItem.AddItem varXRefs(Index) Next Index If Me.lstItem.ListCount > 0 Then Me.lstItem.ListIndex = 0 Me.cmdInsert.Enabled = True Else Me.cmdInsert.Enabled = False End If End Sub -- Windows XP, Word 2003
From: Doug Robbins - Word MVP on 17 Mar 2010 20:19 Yes, that was what I meant I just knocked up a userform with a list box (Listbox1) and a command button containing the following code: ListBox1.List = ActiveDocument.GetCrossReferenceItems _ (ReferenceType:=wdRefTypeHeading) Note: You can just set the .List attribute of a List to an array; there is no need to iterate through the array and use the AddItem command and then running it on a document that contained many more than 10 headings, it populated the listbox with all of the headings. If you want to send me the document from which you are trying to populate the list, I will take a look and see if there is anything peculiar about it that might be causing the problem You can send it to dkr[atsymbol]mvps[dot]org -- 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, originally posted via msnews.microsoft.com "Bear" <david.chinell(a)ge.com(nospam)> wrote in message news:313A40E0-DF7F-4C33-A051-F721BF2414E5(a)microsoft.com... > Doug: > > I hope by that you meant you wanted to see the code. It's in a custom > userform. Here it is. When I hit this sub, I've already loaded the > varRefType > with the type I've selected by clicking an option button. > > This works perfectlly when I step through it after clicking to select > "Chapter". I get ten items in the list. But when I run it I only get two > items in the list. I've used debug.print to determine that the ubound of > varXRefs is 10 when I step it, and 2 when I run it. > > I don't think it's a code problem, because it works perfectly with Word > 2000, but not Word 2003. After I put the DoEvents statement in about six > months ago, it worked for Word 2003 as well. But now it's stopped working. > > I'm looking for a known issue where the method is sometimes flakey, and > for > a workaround. > > (Declarations) > > Dim varXRefs As Variant > > Sub UpdateItemList() > > ' Use varRefType to fill the Item list accordingly > > Me.lstItem.Clear > > ' Prevent a partial or empty Item list in Word 2003 > DoEvents > > varXRefs = ActiveDocument.GetCrossReferenceItems _ > (ReferenceType:=varRefType) > For Index = 1 To UBound(varXRefs) > Me.lstItem.AddItem varXRefs(Index) > Next Index > > If Me.lstItem.ListCount > 0 Then > Me.lstItem.ListIndex = 0 > Me.cmdInsert.Enabled = True > Else > Me.cmdInsert.Enabled = False > End If > > End Sub > > > -- > Windows XP, Word 2003 > >
From: Bear on 18 Mar 2010 12:46 Doug: Thanks for the tip about setting the .List attribute to the array directly! I'm working on the idea that the behavior may be due to the code being in a userform. I tried this: Sub x() Dim varXRefs As Variant varXRefs = ActiveDocument.GetCrossReferenceItems _ (ReferenceType:="Chapter") MsgBox "Loaded: " & Str(UBound(varXRefs)) End Sub And almost every time I run it, I get an accurate count of the chapters in the manual. But I swear I ran it once after doing something in the VBE (can't remember what, but probably not directly related) and the ubound was 2 (the wrong number). But every time after that it was 11 (the right number). I'm still poking around and will let you know if I find anything. Bear -- Windows XP, Word 2000 "Doug Robbins - Word MVP" wrote: > Yes, that was what I meant > > I just knocked up a userform with a list box (Listbox1) and a command button > containing the following code: > > ListBox1.List = ActiveDocument.GetCrossReferenceItems _ > (ReferenceType:=wdRefTypeHeading) > > Note: You can just set the .List attribute of a List to an array; there is > no need to iterate through the array and use the AddItem command > > and then running it on a document that contained many more than 10 headings, > it populated the listbox with all of the headings. > > If you want to send me the document from which you are trying to populate > the list, I will take a look and see if there is anything peculiar about it > that might be causing the problem > > You can send it to dkr[atsymbol]mvps[dot]org > > -- > 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, originally posted via msnews.microsoft.com > > "Bear" <david.chinell(a)ge.com(nospam)> wrote in message > news:313A40E0-DF7F-4C33-A051-F721BF2414E5(a)microsoft.com... > > Doug: > > > > I hope by that you meant you wanted to see the code. It's in a custom > > userform. Here it is. When I hit this sub, I've already loaded the > > varRefType > > with the type I've selected by clicking an option button. > > > > This works perfectlly when I step through it after clicking to select > > "Chapter". I get ten items in the list. But when I run it I only get two > > items in the list. I've used debug.print to determine that the ubound of > > varXRefs is 10 when I step it, and 2 when I run it. > > > > I don't think it's a code problem, because it works perfectly with Word > > 2000, but not Word 2003. After I put the DoEvents statement in about six > > months ago, it worked for Word 2003 as well. But now it's stopped working. > > > > I'm looking for a known issue where the method is sometimes flakey, and > > for > > a workaround. > > > > (Declarations) > > > > Dim varXRefs As Variant > > > > Sub UpdateItemList() > > > > ' Use varRefType to fill the Item list accordingly > > > > Me.lstItem.Clear > > > > ' Prevent a partial or empty Item list in Word 2003 > > DoEvents > > > > varXRefs = ActiveDocument.GetCrossReferenceItems _ > > (ReferenceType:=varRefType) > > For Index = 1 To UBound(varXRefs) > > Me.lstItem.AddItem varXRefs(Index) > > Next Index > > > > If Me.lstItem.ListCount > 0 Then > > Me.lstItem.ListIndex = 0 > > Me.cmdInsert.Enabled = True > > Else > > Me.cmdInsert.Enabled = False > > End If > > > > End Sub > > > > > > -- > > Windows XP, Word 2003 > > > >
|
Next
|
Last
Pages: 1 2 Prev: undo field code changes Next: Get rid of legacy 2003 custom toolbars in 2007 |