VinceB1 was telling us:
VinceB1 nous racontait que :
>> For pIndex = 1 to 8
>> if len(ActiveDocument.Bookmarks(BOOKMARK_LABEL &
[quoted text clipped - 27 lines]
> TheOneWeWant a bookmark or a integer or even something i have no idea
> about
In that sample code, TheOneWeWant returns a Long
TheOneWeWant = pIndex - 1
because pIndex is a long.
So, to get your bookmark name and content, use:
ActiveDocument.Bookmarks(BOOKMARK_LABEL & cstr(TheOneWeWant)).Range.Text
By the way, for future compatibility and ease of code maintenance, it is
better to use full code and not to rely on default properties. So, since it
seems you are interested in the value of the bookmark, i.e. its text, and
assuming Com1 is defined like this:
Dim Com1 As String
it would be better to use
Com1 = ActiveDocument.Bookmarks("Com1").Range.Text
instead of
Com1 = ActiveDocument.Bookmarks("Com1").Range
unless of course Com1 is defined like this:
Dim Com1 As Range

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
VinceB1 - 08 Sep 2006 13:16 GMT
Ok looking into this im more confused, ive put together what ive got so far
to save confusion
Sub FileSave()
With ActiveDocument
Dim Title As String
Dim Com1 As Range
Dim Com2 As Range 'After here come 3 through 8
Title = ActiveDocument.Bookmarks("Title").Range
Call WriteProp(sPropName:="Title", sValue:=Title) 'Reads from
Bookmark Title and writes to Title field in props
'then i want to read all of the Com values go to the first one with
empty range and write the one before
e.g. com2 is empty but com1 has text go to com2 see that its empty
and therefore use com1.
For pIndex = 1 To 8
If Len(ActiveDocument.Bookmarks(BOOKMARK_LABEL & CStr(pIndex)).
Range) = 0 Then
theOneweWant = pIndex - 1
Exit For
End If
Next
'ActiveDocument.Bookmarks(BOOKMARK_LABEL & CStr(theOneweWant)).Range.text
Call WriteProp(sPropName:="Comments", sValue:=??)
VinceB1 - 08 Sep 2006 13:22 GMT
>Ok looking into this im more confused, ive put together what ive got so far
>to save confusion
[quoted text clipped - 25 lines]
> 'ActiveDocument.Bookmarks(BOOKMARK_LABEL & CStr(theOneweWant)).Range.text
> Call WriteProp(sPropName:="Comments", sValue:=??)
im getting that i have an invalid use of property on the .text after Range.
Jean-Guy Marcil - 08 Sep 2006 15:56 GMT
VinceB1 was telling us:
VinceB1 nous racontait que :
> Ok looking into this im more confused, ive put together what ive got
> so far to save confusion
There are indeed many confusing aspects to your code...
Sub FileSave()
With ActiveDocument
'This statement should precede a block that uses methods/properties of
ActiveDocument, I do not see any in your code.
'And where is the "End With" statement?
'e.g.:
With ActiveDocument
.Save
.Close
End With
Dim Title As String
'Why do you need to define 8 range objects?
'Are you going to manipulate the range or the text in the range?
'If you re going to manipulate the text(As it seems you are doing) you
should be declaring String variables
'Also, I do not see any of these being used in the code you posted...
Dim Com1 As Range
Dim Com2 As Range 'After here come 3 through 8
'You have above "With ActiveDocument", and yet you are using ActiveDocument
in this line, in particular reason?
'Above, "Title is defined as aRange, yet you are using the Text (a string)
default proiperty of the Range Property
Title = ActiveDocument.Bookmarks("Title").Range
Call WriteProp(sPropName:="Title", sValue:=Title) 'Reads from
Bookmark Title and writes to Title field in props
'then i want to read all of the Com values go to the first one with
empty range and write the one before
e.g. com2 is empty but com1 has text go to com2 see that its empty
and therefore use com1.
For pIndex = 1 To 8
If Len(ActiveDocument.Bookmarks(BOOKMARK_LABEL &
CStr(pIndex)).
Range) = 0 Then
theOneweWant = pIndex - 1
Exit For
End If
Next
'You commented this line out.... Even if you did not commented it out, it
would not do anything
'You would have to assign the text value of the bookmark range to a
variable, or something...
'ActiveDocument.Bookmarks(BOOKMARK_LABEL & CStr(theOneweWant)).Range.text
Call WriteProp(sPropName:="Comments", sValue:=??)
So, from what I have seen and guesses, here is a potentially useful bit of
code that does what I think you want:
'_______________________________________
Sub FileSave()
Const BOOKMARK_LABEL As String = "Com"
Dim strTitle As String
Dim strBookmark As String
Dim lngIndex As Long
With ActiveDocument
strTitle = .Bookmarks("Title").Range.Text
Call WriteProp(sPropName:="Title", sValue:=strTitle)
For lngIndex = 1 To 8
If Len(.Bookmarks(BOOKMARK_LABEL & CStr(lngIndex)).Range) = 0 Then
If lngIndex = 1 Then
MsgBox "There are not valid bookmarked ranges in this
document."
Else
lngIndex = lngIndex - 1
Exit For
End If
End If
Next
strBookmark = .Bookmarks(BOOKMARK_LABEL & CStr(lngIndex)).Range.Text
Call WriteProp(sPropName:="Comments", sValue:=strBookmark)
End With
End Sub
'_______________________________________

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
Jezebel - 08 Sep 2006 23:52 GMT
> By the way, for future compatibility and ease of code maintenance, it is
> better to use full code and not to rely on default properties.
You might be right in respect of maintenance, and I guess it's wise in code
for beginners to be explicit. But:
1. There's no future compatability issue. Once the VBA-writers have settled
on a default property, they're stuck with it unless they choose to forego
backward compatability. And if they do decide that (which eventually, they
will) your code probably isn't going to run anyway.
2. Using the default property is more efficient, particularly if your
variable is declared 'as object'. There are some GetTickCount tests around
that compare the two methods, and there is a measurable (albeit not, in most
contexts, terribly significant) difference. The internal logic, apparently,
is that if you specify the property explicitly VBA has to validate it, then
look it up in the table of property pointers for the object, then retrieve
it; if you use the default it simply retrieves it.
Jean-Guy Marcil - 09 Sep 2006 00:21 GMT
Jezebel was telling us:
Jezebel nous racontait que :
>> By the way, for future compatibility and ease of code maintenance,
>> it is better to use full code and not to rely on default properties.
[quoted text clipped - 15 lines]
> property pointers for the object, then retrieve it; if you use the
> default it simply retrieves it.
Thanks for your thoughts... My only concern is that I do not know all the
default properties... so I do not take chances...I am always explicit...my
code is not minor!

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org