PDA

View Full Version : Solved: Using Bookmarks with Words BuiltInDocumentProperties



jammy Bodger
02-08-2007, 10:22 AM
Hi,

I have the got the following VBA code below in a word template. What I would like to do is to add the data in Bookmark ?Quotation_No? to the BuiltInDocumentProperties(wdPropertySubject).

I have searched, tried a number of methods but have been unsuccessful. I would add the number directly from the Quotation number file but not sure how to do this either.

Any assistance would be of help.

Thank you, James

*************************************************************************** ***********************************
Sub AutoNew()


Quotation_No = System.PrivateProfileString("S:\ Forms\Auto Generation of Quotation_No.Txt", _
"MacroSettings", "Quotation_No")

If Quotation_No = "" Then
Quotation_No = 1
Else
Quotation_No = Quotation_No + 1
End If

System.PrivateProfileString("S:\ Forms\Auto Generation of Quotation_No.Txt", "MacroSettings", _
"Quotation_No") = Quotation_No

ActiveDocument.Bookmarks("Quotation_No").Range.InsertBefore Format(Quotation_No, "00#")
ActiveDocument.Bookmarks("Quotation_No1").Range.InsertBefore Format(Quotation_No, "00#")
ActiveDocument.BuiltInDocumentProperties(wdPropertySubject).Value = "The Bookmark Entry"
'ActiveDocument.SaveAs FileName:="S:\Customers\Quotation " & Format(Quotation_No, "00#")


End Sub
*************************************************************************** **************************************

fumei
02-09-2007, 08:41 AM
I am not sure what you are doing.
What I would like to do is to add the data in Bookmark “Quotation_No” to the BuiltInDocumentProperties(wdPropertySubject).

ActiveDocument.BuiltInDocumentProperties("Subject") = _
ActiveDocument.Bookmarks("Quotation_No").Range.Textwill take the Range text of the bookmark, and put it in the BuiltinProperty "Subject".

BTW: the InsertBefore instruction will NOT put the text into that Range.

jammy Bodger
02-09-2007, 10:13 AM
Hi fumei,

Thank you for this, I have just tried it and it works fine.

However, about an hour an half ago I added the following to my original code this also does the job.

Dim Quotation_No As String

ActiveDocument.BuiltInDocumentProperties(wdPropertySubject) = "QN" & Quotation_No

Thanks again, James

fumei
02-09-2007, 10:23 AM
Whatever. As stated, I was not (and still am not) sure of what you are doing. That code does not get the bookmark text, but....whatever. If it works for whatever you are doing, then it works.

jammy Bodger
02-09-2007, 01:05 PM
Hi fumei ,
This is what needed to happen: The document is stored on an Exchange Public Folder. When the post happens I want to be sure that the documents subject properties is populated correctly without any user interaction. Therefore in posting the document to the public folder I?m guaranteed the document subject matches the Exchange Posts subject and not anything else i.e. the Doc Title or first line of the document.

fumei
02-09-2007, 07:10 PM
That seems reasonable. But I fail to see what that has got to do with the code you have posted.

You are picking up Quotation_No as a string value from the text file. You increment it. And now you are putting that as the Subject. Ok. Fine.


I’m guaranteed the document subject matches the Exchange Posts subject and not anything else i.e. the Doc Title or first line of the documentAnd how could Subject be the Doc Title, or first line?????

jammy Bodger
02-10-2007, 02:22 AM
I?ll go into it in more detail: As I?m sure you know if you have created a new Word document and then close it. You are naturally prompted to save the document. If you have entered text into the document properties ?Title?. Then this becomes the default prompt text to save the document as its file name. However, if there is no text entered into the document properties title. Then the first line of the documents text is used as the prompt until there is a punctuation mark, whether that is a full stop, comma or apostrophe etc.

When a document has already been saved and is then posted to the exchange public folder. The file name becomes the posting subject which cannot be changed once it has been posted. The Outlook subject field in the public folder is not the same as the Words ?subject? field which in Outlook is called ?Document Subject?. The documents subject field can be changed through opening up the document and changing the subject text box of the document properties, as do all the other words document property fields. The posted filename i.e. the ?subject? also becomes the conversational topic in that folder. This then means that any post item initiated from the posted document, or any mail item that has been created with the same subject line can be grouped together, using the conversational field. A very useful feature, if you need to keep track of internal communications via the post item or external communications via the mail item. You also can use the flag and follow up flag features of Outlook directly on the document just like your inbox providing you have in cell editing turn on in the current folder view.

On with the working process: I have an Outlook com add-in installed. On the contacts form I can click a button, which will initiate the open new office document dialogue box, I then select the new quotation template. The document immediately opens up and wants to post the item to the public folder. However before it can post to the public folder it presents me with the document properties to fill in. In this case, it is the documents subject properties that will become the file name and the Outlook subject name.

I needed the code to generate a sequentially numbered quotation document on opening. The number also needed to appear in the documents subject properties box automatically prior to posting which is automated and immediate once I click the OK button on the document properties. The automatic posting of the document is done via the Outlook com add-in. In this scenario words subject the properties takes priority are title properties. If nothing is entered into the subject or title fields. Then when the document is automatically posted I end up with ?Document1.doc? as the Outlook subject - really not much use at all.

I hope this gives the background and intended use of the code which does the job nicely. :content:

Regards James

fumei
02-10-2007, 05:49 PM
Thank you. It is nice to get a full answer. Now I understand what you are doing.