|
| View previous topic :: View next topic |
| Author |
Message |
JustALittleHelp Guest
|
Posted: Fri Oct 12, 2007 5:51 pm Post subject: Re: Saving A multi Page Doc? |
|
|
2 part question:
Is this specific to Word 2003 or up? I get an error with the line:
Target.SaveAs FileName:=DocName
I modified the following only:
DocName = "C:\MergedSplit\" & Source.Bookmarks("\Line").Range
(didn't like the right bracket after Range and I'm trying to send it to a
specific path.)
Is there a way to maintain the page setup of the originating document, i.e.,
orientation and margins?
This is so amazingly helpful!
Michele
I apologize if this is redundant.
"Doug Robbins - Word MVP" wrote:
| Quote: | The following should do it:
Sub splitter()
'
' splitter Macro
' Macro created 16-08-98 by Doug Robbins to save each page of a document
' as a separate file with the name Page#.DOC
'
Dim Counter As Long, Source As Document, Target As Document
Set Source = ActiveDocument
Selection.HomeKey Unit:=wdStory
Pages = Source.BuiltInDocumentProperties(wdPropertyPages)
Counter = 0
While Counter < Pages
Counter = Counter + 1
DocName = Source.Bookmarks("\Line").Range)
Source.Bookmarks("\Page").Range.Cut
Set Target = Documents.Add
Target.Range.Paste
Target.SaveAs FileName:=DocName
Target.Close
Wend
End Sub
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
"Robert_L_Ross" <RobertLRoss@discussions.microsoft.com> wrote in message
news:61A0D12B-08C7-49F6-BF2A-5B321E5B0650@microsoft.com...
So Doug...
Is there a way to take the first line of each page and have that be the
document name...or something the code can use to create the document name?
"Doug Robbins - Word MVP" wrote:
Sub splitter()
'
' splitter Macro
' Macro created 16-08-98 by Doug Robbins to save each page of a document
' as a separate file with the name Page#.DOC
'
Dim Counter As Long, Source As Document, Target As Document
Set Source = ActiveDocument
Selection.HomeKey Unit:=wdStory
Pages = Source.BuiltInDocumentProperties(wdPropertyPages)
Counter = 0
While Counter < Pages
Counter = Counter + 1
DocName = "Page" & Format(Counter)
Source.Bookmarks("\Page").Range.Cut
Set Target = Documents.Add
Target.Range.Paste
Target.SaveAs FileName:=DocName
Target.Close
Wend
End Sub
--
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
"Lime" <Lime@discussions.microsoft.com> wrote in message
news:6B9A19CF-463A-4DC9-A5AC-6BE003EC7EC0@microsoft.com...
Hello,
I have a 93 page doc. I need to save each page as an individual
document.
Is
there any way to do that without coping and pasting each page? Perhaps
with
some code?
Thanks,
Lime
|
|
|
| Back to top |
|
 |
Google Sponsor

|
Posted: Fri Oct 12, 2007 5:51 pm Post subject: Advertisement |
|
|
|
|
| Back to top |
|
 |
JayM Guest
|
Posted: Tue Oct 16, 2007 8:53 am Post subject: Re: Paper Bins by DriverName |
|
|
Jonathan
Thanks for the reply.
Unfortunately I still can't get it to work.
Because of the pre-printed letterhead on the HP printers we need to Rotate
the paper (Rotated is an option on the Basics tab in the printing
preferences).
I have searched and searched for info on this but can't find it - do you
know where I might be able to get advice on this one
At the moment I have a macro that stops so the user can change printer(or
profile) with the duplex and rotated settings on and then stops after the
print to reset it.
JayM
"Jonathan West" wrote:
| Quote: |
"JayM" <JayM@discussions.microsoft.com> wrote in message
news:B77E5274-F8E5-4A6F-9D75-D0915571FEA9@microsoft.com...
Ok so the citrix thing I will have to think about then!!!
On a slightly different note. I have been looking at your article for
printing duplex which works great except ......
when using pre-printed letterheads to print double sided.
In our sharp printer/copiers it is not a problem but with the HP Laserjets
you have to tell it to print with the paper rotated.
Is there anyway to control this using vba?
The second article in the series describes how to control the duplex setting
of the printer. Different values determine which way up the text is printed
on the reverse side. Since I wrote the article, I have come across an
occasional printer that has nonstandard values for the Duplex property, so
you'll need to check that out. Try setting the duplex property by hand
through the printer properties dialog so that it prints the way you want,
and then use code to read the resulting value of the duplex setting.
--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
|
|
|
| Back to top |
|
 |
JayM Guest
|
Posted: Thu Oct 18, 2007 11:02 am Post subject: Re: Paper Bins by DriverName |
|
|
Jonathan
Many thanks for all your help with my many printing queries - unfortunately
I have another one for you.
I have written a macro to use your duplexing code and this works fine
locally but when using word in Citrix it seems to ignore the duplex code. At
the moment Citrix just has a universal driver and each pc has the printer
installed locally if this is of any help.
JayM
"Jonathan West" wrote:
| Quote: |
"JayM" <JayM@discussions.microsoft.com> wrote in message
news:CB2DD395-8709-40A9-8FE0-B49FCEA5A31B@microsoft.com...
Jonathan
Thanks again so much for your help with my macros they work a treat now.
My next challenge is that we have some offices working over citrix using a
Citrix Universal Printer driver. Have you any ideas how I could get my
macros to work with these.
Ouch! I tend to shudder somewhat whenever I learn that my templates are
goijg to have to work over Citix - it always seems to cause additional
problems.
I think the first thing to find out is whether the existing
GetPrinterDetails code will work with the Citrix universal driver. If so,
the problem is simply to work out what tray IDs you need to use.
If the GetPrinterDetails code *doesn't* work, then you need to think of a
way in which a Citrix universal driver can be distinguished from a "real"
printer. So long as there is some means of making that distinction, then you
can assign tray IDs accordingly.
However, there is one further wrinkle you might need to consider. The Citrix
universal driver presumably is managing print queues rather than individual
printers, and the Citrix server in fact has conventional printer drivers
which manage the physical printers, and print jobs are passed to the
conventional driver by the Citrix universal driver. The Citrix universal
driver might simply pass through the tray IDs to the conventional driver, in
which case you will have to follow one of two possible routes.
1. Ensure that all the printers associated with a particuar identifiable
Citrix queue are of the same known type, so you can use known tray IDs when
printing to that queue.
2. Find some way of identifying the physical printer to be used, and setting
the tray IDs accordingly.
Without knowledge of your particular system, I don't think I can offer any
more specific advice than this.
--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
|
|
|
| Back to top |
|
 |
Mickey Guest
|
Posted: Thu Nov 01, 2007 9:53 pm Post subject: Re: Cross Reference Macro to Current Paragraph |
|
|
I know I'm getting into this late but could this code be modified to create a
cross reference based on existing bookmarks in the document. The situation
is this....I have multiple headers in a document due to portrait and
landscape pages. There are 4 bookmarks in the header (DOC_NAME, DOC_VERSION,
DOC_TITLE, DOC_SITE). The headers each need the same bookmarks. I have a
macro to add the bookmarks but the bookmarks are only retained in the last
header. I'm wondering if I can search the headers where the bookmark was
lost and include cross reference code. For example, search for "[DOC_NAME]
and have code that cross references it to the bookmark DOC_NAME.
Any help is very much appreciated.
Thanks,
Mickey
"Russ" wrote:
| Quote: | Kurtis,
You could try:
Dim n as Long
Dim myBookmark as String
n = ActiveDocument.Bookmarks.Count + 1
myBookmark = "b" & Cstr(n)
Then replace "b" in your code below with the variable myBookmark, verbatim
(without quotation marks), in both places.
Here is the new code:
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="b"
.DefaultSorting = wdSortByLocation
.ShowHidden = True
End With
Selection.InsertCrossReference ReferenceType:="Bookmark",
ReferenceKind:= _
wdNumberFullContext, ReferenceItem:="b", InsertAsHyperlink:=True, _
IncludePosition:=False
End Sub
Is there a way to generate a new bookmark Name (in this case "b") and copy
it to the ReferenceItem (b) each time the macro is run?
"Kurtis" wrote:
Thanks for your response. That makes sense, but how do I automate the
process? How can I make it reflect the correct paragraph context each time
the macro is run?
"macropod" wrote:
Hi Kurtis,
The ReferenceItem will be a bookmark - either one you've created or one that
Word has created and for which you know the ID/Name.
Cheers
--
macropod
[MVP - Microsoft Word]
"Kurtis" <Kurtis@discussions.microsoft.com> wrote in message
news:0612552C-D1F0-4DD3-B747-C2CF5413A3DF@microsoft.com...
I am having a problem with a cross reference and would really appreciate
some
help. What I am trying to do is create a macro that will insert a full
context cross reference that references the current paragraph. For
instance,
par. 3.5 states "except as provided on Schedule 3.5. Here is my code so
far:
Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdNumberFullContext, ReferenceItem:="?",
InsertAsHyperlink _
:=True, IncludePosition:=False
End Sub
Any help on this would be greatly appreciated.
--
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID
|
|
|
| Back to top |
|
 |
Russ Guest
|
Posted: Sun Nov 04, 2007 7:43 am Post subject: Re: Cross Reference Macro to Current Paragraph |
|
|
Mickey,
I think your question was answered by Tony in the other thread:
"Retaining Bookmarks in Autotext Macros"
| Quote: | I know I'm getting into this late but could this code be modified to create a
cross reference based on existing bookmarks in the document. The situation
is this....I have multiple headers in a document due to portrait and
landscape pages. There are 4 bookmarks in the header (DOC_NAME, DOC_VERSION,
DOC_TITLE, DOC_SITE). The headers each need the same bookmarks. I have a
macro to add the bookmarks but the bookmarks are only retained in the last
header. I'm wondering if I can search the headers where the bookmark was
lost and include cross reference code. For example, search for "[DOC_NAME]
and have code that cross references it to the bookmark DOC_NAME.
Any help is very much appreciated.
Thanks,
Mickey
"Russ" wrote:
Kurtis,
You could try:
Dim n as Long
Dim myBookmark as String
n = ActiveDocument.Bookmarks.Count + 1
myBookmark = "b" & Cstr(n)
Then replace "b" in your code below with the variable myBookmark, verbatim
(without quotation marks), in both places.
Here is the new code:
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="b"
.DefaultSorting = wdSortByLocation
.ShowHidden = True
End With
Selection.InsertCrossReference ReferenceType:="Bookmark",
ReferenceKind:= _
wdNumberFullContext, ReferenceItem:="b", InsertAsHyperlink:=True, _
IncludePosition:=False
End Sub
Is there a way to generate a new bookmark Name (in this case "b") and copy
it to the ReferenceItem (b) each time the macro is run?
"Kurtis" wrote:
Thanks for your response. That makes sense, but how do I automate the
process? How can I make it reflect the correct paragraph context each time
the macro is run?
"macropod" wrote:
Hi Kurtis,
The ReferenceItem will be a bookmark - either one you've created or one
that
Word has created and for which you know the ID/Name.
Cheers
--
macropod
[MVP - Microsoft Word]
"Kurtis" <Kurtis@discussions.microsoft.com> wrote in message
news:0612552C-D1F0-4DD3-B747-C2CF5413A3DF@microsoft.com...
I am having a problem with a cross reference and would really appreciate
some
help. What I am trying to do is create a macro that will insert a full
context cross reference that references the current paragraph. For
instance,
par. 3.5 states "except as provided on Schedule 3.5. Here is my code so
far:
Selection.InsertCrossReference ReferenceType:="Numbered item", _
ReferenceKind:=wdNumberFullContext, ReferenceItem:="?",
InsertAsHyperlink _
:=True, IncludePosition:=False
End Sub
Any help on this would be greatly appreciated.
--
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID
|
--
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID |
|
| Back to top |
|
 |
Guest
|
Posted: Mon Nov 05, 2007 7:53 pm Post subject: solution to Word 2007 BUG options.printbackground failure |
|
|
I posted this question several months ago (under y dmitri karpov account), and have finally stumbled on the answer.
There is a bug in Word 2007.
If the username and initials fields are not filled in, then for some inexplicable reason, the VBA code
options.printbackground
will fail to execute with a bad parameter error.
Custom solutions that require this code for printing will fail silently (or with a bad parameter error).
The solution: have the user put their username and initials in word. Close word. Try again.
I have reported this bug to Microsoft.
EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com |
|
| Back to top |
|
 |
Russ Guest
|
Posted: Tue Nov 06, 2007 6:44 am Post subject: Re: solution to Word 2007 BUG options.printbackground failur |
|
|
Thanks for the feedback.
| Quote: | I posted this question several months ago (under y dmitri karpov account), and
have finally stumbled on the answer.
There is a bug in Word 2007.
If the username and initials fields are not filled in, then for some
inexplicable reason, the VBA code
options.printbackground
will fail to execute with a bad parameter error.
Custom solutions that require this code for printing will fail silently (or
with a bad parameter error).
The solution: have the user put their username and initials in word. Close
word. Try again.
I have reported this bug to Microsoft.
EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com
|
--
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID |
|
| Back to top |
|
 |
Tyll Guest
|
Posted: Tue Nov 06, 2007 2:30 pm Post subject: Re: solution to Word 2007 BUG options.printbackground fail |
|
|
Dmitri,
Also see the thread "Word 2007: Options.ReplaceSelection -> Run-time
error 4120 Bad Parameter" from 10/19/07 which contains more extensive
documentation of the bug and the solution.
Regards, Tyll. |
|
| Back to top |
|
 |
Hans Guest
|
Posted: Tue Nov 06, 2007 4:14 pm Post subject: Re: solution to Word 2007 BUG options.printbackground failur |
|
|
Here's a code sample to work around the bug:
Private Sub OfficeUserName()
'User name bug solution
'Validate user name and ask for a correction if needed
Dim MsgText As String
Dim dlgUserInfo As Dialog
Set dlgUserInfo = Dialogs(wdDialogToolsOptionsUserInfo)
MsgText = "An invalid user name was found in Word Options. "
MsgText = MsgText & "Please type in your name!"
Again:
With dlgUserInfo
If Not ValidateUsername(.Name) Then
.Name = InputBox(MsgText, "[My Add-In]", "[Your name]")
If ValidateUsername(.Name) Then
.Execute
Else
GoTo Again
End If
End If
End With
End Sub
Private Function ValidateUsername(OffUserName As String) As Boolean
'A valid user name needs to have at least one character
'which is not a blank space
If Len(OffUserName) >= 1 Then
For I = 1 To Len(OffUserName)
If Mid(OffUserName, I, 1) <> " " Then
ValidateUsername = True
End If
Next
End If
End Function
Regards, Hans
<Dmitri Karpov> schrieb im Newsbeitrag
news:2007115145340maxl@compusenseinc.com...
| Quote: | I posted this question several months ago (under y dmitri karpov account),
and have finally stumbled on the answer.
There is a bug in Word 2007.
If the username and initials fields are not filled in, then for some
inexplicable reason, the VBA code
options.printbackground
will fail to execute with a bad parameter error.
Custom solutions that require this code for printing will fail silently
(or with a bad parameter error).
The solution: have the user put their username and initials in word. Close
word. Try again.
I have reported this bug to Microsoft.
EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com |
|
|
| Back to top |
|
 |
Guest
|
Posted: Thu Nov 08, 2007 7:48 pm Post subject: GetCrossReferenceItems and sparse returns for wdCaptionTable |
|
|
Try this:
Set myRange = ActiveDocument.Range(Start:=0, End:=0)
oCaptions = _
ActiveDocument.GetCrossReferenceItems(wdCaptionTable)
....or wdCaptionFigure
I found that if a range was not set, then only about 9 elements would be returned, and those 9 elements correspond to the first 9 elements in the displayed cross reference window.
Good Luck
EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com |
|
| Back to top |
|
 |
MIrving Guest
|
Posted: Fri Nov 09, 2007 3:32 am Post subject: Re: Checkbox -- delete or keep text |
|
|
Hi Greg
I found your macro perfect for deleting unselected check box paragraphs.
The only additional functionality I would like to add to my document is for
the remaining check boxes (ie. the checked boxes) to also be deleted, leaving
only the paragraph text for the selected items. Is there anyway of achieving
this? Thank you for any suggestions.
"Greg" wrote:
| Quote: | Try something like this:
Sub Test()
Dim oPar As Paragraph
On Error Resume Next
ActiveDocument.Unprotect
On Error GoTo 0
For Each oPar In ActiveDocument.Paragraphs
If oPar.Range.FormFields(1).CheckBox.Value = False Then
oPar.Style = "Hidden"
Else
oPar.Style = "Normal"
End If
Next
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, noreset:=True
End Sub
This looks at the value of the "first" checkbox in each paragraph.
Add the macro to a toolbar button or keyboard shortcut.
|
|
|
| Back to top |
|
 |
Shauna Kelly Guest
|
Posted: Fri Nov 09, 2007 8:58 am Post subject: Re: GetCrossReferenceItems and sparse returns for wdCaptionT |
|
|
Hi Greg
I'm interested in following this up because I've had trouble over the years
using .GetCrossReferenceItems. It doesn't always pick up all items, and I
had to roll my own routine, which runs much slower than the built-in one.
I can't see that
Set myRange = ActiveDocument.Range(Start:=0, End:=0)
is related to
oCaptions = _
ActiveDocument.GetCrossReferenceItems(wdCaptionTable)
But are you saying that setting a range variable to a more or less random
range immediately before running .GetCrossReferenceItems causes it to work
reliably? Stranger things have happened in Word, so nothing would surprise
me!
Shauna
Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
<Greg Stanford> wrote in message news:200711814489no_spam_thanks@com...
| Quote: | Try this:
Set myRange = ActiveDocument.Range(Start:=0, End:=0)
oCaptions = _
ActiveDocument.GetCrossReferenceItems(wdCaptionTable)
...or wdCaptionFigure
I found that if a range was not set, then only about 9 elements would be
returned, and those 9 elements correspond to the first 9 elements in the
displayed cross reference window.
Good Luck
EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com |
|
|
| Back to top |
|
 |
Bob W Guest
|
Posted: Fri Nov 09, 2007 3:21 pm Post subject: RE: autotextlist not working as expected |
|
|
There's definitely some Twilight Zone things that can happen to
autotextlists. In my experience, although they offer great promise for
simplifying work, they often tend to get mysteriously corrupted over time,
even when carefully stored in a template (other than Normal.dot) attached to
a document. Sometimes one or more unintended autotext items mysteriously
start appearing in the autotext dropdown, even though they were never defined
in that autotext list! Sometimes one, or all, of my autotext fields,
suddenly start showing me ALL my autotext items, not just the ones I defined
in an Autotext List. In one case, after working properly for many weeks, I
suddenly notice that when I clicked on the field for Autotextlist A, the
autotext list items that I had defined for Autotext List B were appearing
instead of the the items I had so tediously defined for Autotext List A! For
these reasons, I've very regrettably begun moving away from autotext lists -
they take a lot of time to set up, and when they get mysteriously corrupted,
fixing them takes at least as long again. I am pretty sure they don't save
much time, overall, because of the hassles involved with creating and
maintaining them. At one time I thought they were going to be very helpful
to our workgroup and rolled out some templates to help the team work faster,
with some autotext list items in them. They worked for a while, and then
problems like I've described, above, started happening. Autotextlists exist
and reside kind of in the background, and lack convenient dialogs that might
otherwise make them easy to create and manage. To me, although they appear
to be a great novelty feature and a source of interesting discussions among
Word MVPs in theory, putting these kinds of features into serious, reliable
practice has been disappointing, at least for me, despite the enormous
patience and time I've expended on them. Other users may disagree, but I have
reluctantly come to feel that they are not robust enough - or, maybe, at
least in my case, idiot-proof enough - for Prime Time usage.
"Ed" wrote:
| Quote: | Hi JSG,
I don't know if this is relevant to your situation, but the following seems
to be true (for me) ...
I can save autotext entries into normal.dot, a template which is in my Word
startup folder, a template I have loaded through Tools>Templates and Addins,
or a template I've opened (e.g. by means of File>Open).
If I try to create autotext entries in a template which is just the attached
template of the document I have open, then, when I close the document, if I
opt not to save the changes to the document, Word seems not to save the
changes (autotext) to the attached template and the autotext entries are
lost. If I opt to save the changes to the document, Word prompts me to save
the changes to the attached template and (if I opt to save them) the autotext
entries are retained.
Regards.
Ed
"JustSomeGuy" wrote:
Thanks, Ed - several hours of working with autotext lists got me pretty good
at spotting things like missing double quotes and other typos. Stil not sure
why the wrong items were appearing in my autotext list, but I found that when
it sometimes happens I have to re-do an entire autotextlist from scratch,
including re-defining the unique style used for it.
"Ed" wrote:
Oops!
Should have mentioned that as soon as I had created the autotext entries the
field worked as intended.
Cheers.
Ed
"JustSomeGuy" wrote:
For a letter, I want to present three possible addressee first names in an
autotext list that appears in the letter template with the literal text,
"Addressee", the three possibile first names formatted with a special style
named 'ATAddressee", and the tip text stating, "Select Addressee".
The syntax I've written is as follows:
{AUTOTEXTLIST "Addressee" \s "ATAddressee" \t\"Select Addressee: }
I used Ctrl-F9 to generate the curly brackets.
When I hover over the resulting literal text, the desired screen tip text
appears, but when I right-click on the field, I get a dropdown list of all my
autotext entries EXCEPT FOR the Addresse entries I wanted to appear., even
though none of the unwanted autotext entries in the dropdown have been
assigned the style, "ATAddressee".
Supposedly, I should only be seeing those three addressees, because they are
the only ones formatted with the style I specified in the AutotextList
syntax.
What am I doing wrong?
|
|
|
| Back to top |
|
 |
Russ Guest
|
Posted: Fri Nov 09, 2007 7:17 pm Post subject: Re: GetCrossReferenceItems and sparse returns for wdCaptionT |
|
|
Shauna et al.,
Here's what VBA help says about .GetCrossReferenceItems in my version of
Word. The asterisks were added by me for emphasis.
Although it says "for which box", it later only gives 5 types. Because
wdCaptionTable is not a wdRefCaptionTable type, maybe it is unreliable?
Maybe everything in the "for which box" has not been fully integrated or
debugged to work with that method yet?
===Quote
Returns an array of items that can be cross-referenced based on the
specified cross-reference type. The array corresponds to the items listed in
the **For which box** in the Cross-reference dialog box (Insert menu).
Note An item returned by this method can be used as the ReferenceWhich
argument for the InsertCrossReference method.
Syntax
expression.GetCrossReferenceItems(ReferenceType)
expression Required. An expression that returns a Document object.
ReferenceType Required Variant. The type of item you want to insert a
cross-reference to. Can be one of the following WdReferenceType constants:
**wdRefTypeBookmark, wdRefTypeEndnote, wdRefTypeFootnote, wdRefTypeHeading,
or wdRefTypeNumberedItem**.
====UnQuote
| Quote: | Hi Greg
I'm interested in following this up because I've had trouble over the years
using .GetCrossReferenceItems. It doesn't always pick up all items, and I
had to roll my own routine, which runs much slower than the built-in one.
I can't see that
Set myRange = ActiveDocument.Range(Start:=0, End:=0)
is related to
oCaptions = _
ActiveDocument.GetCrossReferenceItems(wdCaptionTable)
But are you saying that setting a range variable to a more or less random
range immediately before running .GetCrossReferenceItems causes it to work
reliably? Stranger things have happened in Word, so nothing would surprise
me!
Shauna
Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
Greg Stanford> wrote in message news:200711814489no_spam_thanks@com...
Try this:
Set myRange = ActiveDocument.Range(Start:=0, End:=0)
oCaptions = _
ActiveDocument.GetCrossReferenceItems(wdCaptionTable)
...or wdCaptionFigure
I found that if a range was not set, then only about 9 elements would be
returned, and those 9 elements correspond to the first 9 elements in the
displayed cross reference window.
Good Luck
EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com
|
--
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID |
|
| Back to top |
|
 |
Shauna Kelly Guest
|
Posted: Sat Nov 10, 2007 2:03 am Post subject: Re: GetCrossReferenceItems and sparse returns for wdCaptionT |
|
|
Hi Russ
I think it's a bit more complicated than that and the documentation in VBA
help is, shall we say, incomplete.
The array that you get back from GetCrossReferenceItems is equivalent to the
"For which" box. The Reference Type you must give it is equivalent to the
"Reference Type" box in the dialog.
The "Reference Type" box includes caption labels. But none of the
wdReferenceType constants cope with caption labels. And obviously you can
create a cross-reference to, eg, a Table or Figure or Equation caption. So
you can use a string, eg:
Dim va As Variant
va = ActiveDocument.GetCrossReferenceItems("Table")
Or, you may have created your own label so you could use
Dim va As Variant
va = ActiveDocument.GetCrossReferenceItems("MyLabel")
Unlike "MyLabel", the Table, Figure and Equation labels are built-in. And
they have their own wdCaptionLabelID constants, wdCaptionTable,
wdCaptionFigure, wdCaptionEquation.
In an English install,
va = ActiveDocument.GetCrossReferenceItems("Table")
should produce the same results as
va = ActiveDocument.GetCrossReferenceItems(wdCaptionTable)
But since "Table" isn't "Table" except in English, it's safer to use the
constants.
But I have found in a large document with many tables, that
GetCrossReferenceItems does not always return an array containing an element
for all the tables in the document. It will do the first 100 or so tables,
but not the rest. It's not reproducible, and it seems to depend on document
complexity rather than sheer size. And, I don't think it's related to
hardware grunt, since giving it more processor speed and memory doesn't
solve the problem.
So I'm wondering if Greg found some mysterious way to solve that problem.
Shauna
Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
"Russ" <drsN0SPAMmikle@hotmailD0Tcom.INVALID> wrote in message
news:C35A1C78.1EFA4%drsN0SPAMmikle@hotmailD0Tcom.INVALID...
| Quote: | Shauna et al.,
Here's what VBA help says about .GetCrossReferenceItems in my version of
Word. The asterisks were added by me for emphasis.
Although it says "for which box", it later only gives 5 types. Because
wdCaptionTable is not a wdRefCaptionTable type, maybe it is unreliable?
Maybe everything in the "for which box" has not been fully integrated or
debugged to work with that method yet?
===Quote
Returns an array of items that can be cross-referenced based on the
specified cross-reference type. The array corresponds to the items listed
in
the **For which box** in the Cross-reference dialog box (Insert menu).
Note An item returned by this method can be used as the ReferenceWhich
argument for the InsertCrossReference method.
Syntax
expression.GetCrossReferenceItems(ReferenceType)
expression Required. An expression that returns a Document object.
ReferenceType Required Variant. The type of item you want to insert a
cross-reference to. Can be one of the following WdReferenceType constants:
**wdRefTypeBookmark, wdRefTypeEndnote, wdRefTypeFootnote,
wdRefTypeHeading,
or wdRefTypeNumberedItem**.
====UnQuote
Hi Greg
I'm interested in following this up because I've had trouble over the
years
using .GetCrossReferenceItems. It doesn't always pick up all items, and I
had to roll my own routine, which runs much slower than the built-in one.
I can't see that
Set myRange = ActiveDocument.Range(Start:=0, End:=0)
is related to
oCaptions = _
ActiveDocument.GetCrossReferenceItems(wdCaptionTable)
But are you saying that setting a range variable to a more or less random
range immediately before running .GetCrossReferenceItems causes it to
work
reliably? Stranger things have happened in Word, so nothing would
surprise
me!
Shauna
Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
Greg Stanford> wrote in message news:200711814489no_spam_thanks@com...
Try this:
Set myRange = ActiveDocument.Range(Start:=0, End:=0)
oCaptions = _
ActiveDocument.GetCrossReferenceItems(wdCaptionTable)
...or wdCaptionFigure
I found that if a range was not set, then only about 9 elements would be
returned, and those 9 elements correspond to the first 9 elements in the
displayed cross reference window.
Good Luck
EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com
--
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|