Arrghhhhhhhh

  • Thread starter OHM \( Terry Burns \)
  • Start date
O

OHM \( Terry Burns \)

Sorry, this is a second post, but now its at the right level

Can someone tell me where to set the following in vb code please

When you open up the document properties. There is a tab called contents in
a blank document the word Title appears, and this can have entries below it.

What does this tab represent
How to access the contents programatically


TIA


--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
 
P

Peter

Try this:

Dim prop As DocumentProperty
Set prop = ActiveDocument.BuiltInDocumentProperties("Title")
prop.Value = "My new Title"

You can also cut out the dim and set statements and simply do:
ActiveDocument.BuiltInDocumentProperties("Title").Value = "My new title"

The above worked for me in Word 2002.

hth,

-Peter
 
O

OHM \( Terry Burns \)

Thanks, but I was doing the equivelent of this anyway. However, in a strange
quirk of fate I stumbled on a solution. It would appear that if you set the
value of a property, ( at least for this particular one ), that it does not
initialise properly, leaving out the property like so works fine.


ActiveDocument.BuiltInDocumentProperties("Title") = "New Title"

Thanks for trying to help anyway, if you know why this is I would be
interested to find the cause


--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"Peter" <peterguy -at- hotmail -dot- com> wrote in message
Try this:

Dim prop As DocumentProperty
Set prop = ActiveDocument.BuiltInDocumentProperties("Title")
prop.Value = "My new Title"

You can also cut out the dim and set statements and simply do:
ActiveDocument.BuiltInDocumentProperties("Title").Value = "My new title"

The above worked for me in Word 2002.

hth,

-Peter
 
O

OHM \( Terry Burns \)

Forget that, it seems to be doing it again, is there some caching issues I
should know about ?

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
OHM ( Terry Burns ) said:
Thanks, but I was doing the equivelent of this anyway. However, in a
strange quirk of fate I stumbled on a solution. It would appear that if
you set the value of a property, ( at least for this particular one ),
that it does not initialise properly, leaving out the property like so
works fine.


ActiveDocument.BuiltInDocumentProperties("Title") = "New Title"

Thanks for trying to help anyway, if you know why this is I would be
interested to find the cause


--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"Peter" <peterguy -at- hotmail -dot- com> wrote in message
Try this:

Dim prop As DocumentProperty
Set prop = ActiveDocument.BuiltInDocumentProperties("Title")
prop.Value = "My new Title"

You can also cut out the dim and set statements and simply do:
ActiveDocument.BuiltInDocumentProperties("Title").Value = "My new title"

The above worked for me in Word 2002.

hth,

-Peter
 
P

Peter

Hmm.... I found that both methods work for me, BUT, I did find what seems to me to be a bug in Word:

When the Title (probably applies to other properties, too) is set, then the document must be saved for the change to apply. Changing a Document Property apparently does not set the document state to dirty, so it is not automatically saved upon closing.

So, using .Value will work, as will your method, you just have to explicitly save the document.

hth,

-Peter

OHM ( Terry Burns ) said:
Thanks, but I was doing the equivelent of this anyway. However, in a strange
quirk of fate I stumbled on a solution. It would appear that if you set the
value of a property, ( at least for this particular one ), that it does not
initialise properly, leaving out the property like so works fine.


ActiveDocument.BuiltInDocumentProperties("Title") = "New Title"

Thanks for trying to help anyway, if you know why this is I would be
interested to find the cause


--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"Peter" <peterguy -at- hotmail -dot- com> wrote in message
Try this:

Dim prop As DocumentProperty
Set prop = ActiveDocument.BuiltInDocumentProperties("Title")
prop.Value = "My new Title"

You can also cut out the dim and set statements and simply do:
ActiveDocument.BuiltInDocumentProperties("Title").Value = "My new title"

The above worked for me in Word 2002.

hth,

-Peter
 
O

OHM \( Terry Burns \)

Actually, the problem is something else completely. I found that my template
somehow had gotten a value in the title field, and if this happen, setting
the Title Field Programatically does not affect the documents content value.

I cleared this and re-ran it, it would seem to work fine. However, from an
academic point of view I would like to know

1.) Why this happens
2.) How to change what appears in the document content tab in the properties
dialog.

Hope you can help, I hate things I dont understand !


--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"Peter" <peterguy -at- hotmail -dot- com> wrote in message
Hmm.... I found that both methods work for me, BUT, I did find what seems to
me to be a bug in Word:

When the Title (probably applies to other properties, too) is set, then the
document must be saved for the change to apply. Changing a Document
Property apparently does not set the document state to dirty, so it is not
automatically saved upon closing.

So, using .Value will work, as will your method, you just have to explicitly
save the document.

hth,

-Peter

OHM ( Terry Burns ) said:
Thanks, but I was doing the equivelent of this anyway. However, in a
strange
quirk of fate I stumbled on a solution. It would appear that if you set
the
value of a property, ( at least for this particular one ), that it does
not
initialise properly, leaving out the property like so works fine.


ActiveDocument.BuiltInDocumentProperties("Title") = "New Title"

Thanks for trying to help anyway, if you know why this is I would be
interested to find the cause


--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"Peter" <peterguy -at- hotmail -dot- com> wrote in message
Try this:

Dim prop As DocumentProperty
Set prop = ActiveDocument.BuiltInDocumentProperties("Title")
prop.Value = "My new Title"

You can also cut out the dim and set statements and simply do:
ActiveDocument.BuiltInDocumentProperties("Title").Value = "My new title"

The above worked for me in Word 2002.

hth,

-Peter
 
P

Peter

The problem is not the title of the template, it's just that you need to explicitly save the document after changing the title.
Simply invoking ActiveDocument.Save isn't enough, since changing the title doesn't make the document "dirty" so .Save does nothing. Before invoking ActiveDocument.Save, invoke ActiveDocument.Saved = False in order to force the document to save. Why changing the title doesn't "dirty" the document beats me.

I put the following sub in the ThisDocument module of a template, then created a document based on it. It changed the title of the document every time (after the initial creation, naturally).

Private Sub Document_Open()
Dim sTitle As String

If ActiveDocument.Type = wdTypeDocument Then

sTitle = ActiveDocument.BuiltInDocumentProperties("Title").Value

MsgBox "Old Title: " & sTitle

On Error Resume Next
sTitle = CStr(CInt(sTitle) + 1)
If Err Then
sTitle = "0"
End If
On Error GoTo 0

MsgBox "New Title: " & sTitle

ActiveDocument.BuiltInDocumentProperties("Title").Value = sTitle
ActiveDocument.Saved = False
ActiveDocument.Save
End If
End Sub

hth,

-Peter
 
O

OHM \( Terry Burns \)

This instantly registers the Title into the contents of the document so its
not lost. I think title seems to be the only property affected because it is
part of the Content listing. I found this by looking in a Letter Wizard an
just tried it as a last straw.

WordBasic.FileSummaryInfo Title:=Me.subjectTextBox.Text

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
 
O

OHM \( Terry Burns \)

These commands were superceeded by the BuiltInProperty collection
DocumentProperty values, however there seems to be some difference in the
way they work.

I know Im missing something here, there must be a way of registering the
title as one of the contents of the document, I just dont know how. I would
like to be able to do this without regressing to Wordbasic command set which
will doubtless be unsupported in a later date.

ALSO

I have noticed with the template I sent you that if you double click on it
to create a new document, it takes a long while to finish up the macro and
get back to the document, whereas if you use the File | New Templates On My
Computer then it works OK.

so . . .

Is double clicking a supported method of working or if not, why would this
be happening?

Sorry for bugging you, but you are almost the only one who has been willing
to help on this .
#

Many Thank - Terry




--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top