Click here to Skip to main content
15,919,613 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Converting from C# to VB.net Pin
Dave Doknjas20-May-05 14:53
Dave Doknjas20-May-05 14:53 
GeneralRe: Converting from C# to VB.net Pin
Kevin McFarlane21-May-05 1:54
Kevin McFarlane21-May-05 1:54 
GeneralRe: Converting from C# to VB.net Pin
Dave Doknjas20-May-05 14:46
Dave Doknjas20-May-05 14:46 
GeneralRe: Converting from C# to VB.net Pin
macca2422-May-05 22:38
macca2422-May-05 22:38 
GeneralRe: Converting from C# to VB.net Pin
Dave Doknjas23-May-05 6:00
Dave Doknjas23-May-05 6:00 
GeneralCreating Setup in VB.NET Pin
meetaqadir19-May-05 23:56
meetaqadir19-May-05 23:56 
GeneralRe: Creating Setup in VB.NET Pin
rudy.net21-May-05 20:41
rudy.net21-May-05 20:41 
GeneralAccessing word CustomDocumentProperties from VB.NET Pin
raph-it19-May-05 23:37
raph-it19-May-05 23:37 
Hi.

I have a VB.NET program that is creating Word documents based on an existing template file by filling in data retrieved from a database. Some of the content in the Word document is maintained in custom properties, however, although it is very easy to manage these from with a Word macro, I am having difficulty getting hold of the CustomDocumentProperties collection from within VB.NET. Originally, I tried having a variable of type Word.CustomProperty which I would use, in conjunction with the CustomDocumentProperties collection, but had absolutely no joy. Am I being stupid and missing something very obvious.

The problem seems to be that for some reason, CustomDocumentProperties is of type System.__COMObject and does not have any discernable methods or properties. For now, I have created a single line word macro (as part of the original template) that simply sets a custom property to the value you desire, but this is far from ideal, and really goes against the grain for me!! Unfortunately, this is not a solution that can be entirely coded in Word as it is essentially a very small part of a bigger solution (the word doc is just something that is produced at the same time as other things)

Does anyone have any experience with CustomDocumentProperties from VB.NET when talking to Office 2003. I prefer to use Option Strict On, but if it is necessary to turn it off, I will!

A code snippet from .NET that I am using (simplyfied) is shown below. Any help with this would be greatly appreciated Big Grin | :-D
Imports Word = Microsoft.Office.Interop.Word
..
..
..
Dim oWord As Word.ApplicationClass
Dim docCurrent As Word.Document
'
' Start MS Word and open the document.
'
oWord = CType(CreateObject("Word.Application"), Word.ApplicationClass)
docCurrent = oWord.Documents.Open(FileName:="C:\MyOriginalDoc.doc", ReadOnly:=True)
'
' Since it seems impossible to get to the CustomDocumentProperties collection with the Word
' object Model through VB.NET, we run a little macro that is embedded in the template to
' populate the custom properties. Not nice, but apparently necessary - although I won't be
' defeated, so whatch this space!
'
oWord.Run("SetDocProperty", "PhaseDescription", strPhaseDesc)
'
' And now we update the fields
'
docCurrent.Fields.Update()

oWord.Options.PrintFieldCodes = False

docCurrent.PrintOut()
docCurrent.SaveAs("c:\MyNewDocument.doc")

'Quit Word.
oWord.Quit()

Marshal.ReleaseComObject(oWord)

oWord = Nothing

Generalproblem in progamming microsoft word Pin
IvanChang19-May-05 22:04
IvanChang19-May-05 22:04 
GeneralRe: problem in progamming microsoft word Pin
niansah20-May-05 4:21
niansah20-May-05 4:21 
GeneralRe: problem in progamming microsoft word Pin
IvanChang20-May-05 14:28
IvanChang20-May-05 14:28 
GeneralRe: problem in progamming microsoft word Pin
IvanChang20-May-05 17:35
IvanChang20-May-05 17:35 
Generalproblem with data reports in vb Pin
Member 197900819-May-05 21:03
Member 197900819-May-05 21:03 
GeneralGiving Input to printer Pin
mahendren8419-May-05 19:12
mahendren8419-May-05 19:12 
GeneralRe: Giving Input to printer Pin
toxcct20-May-05 3:19
toxcct20-May-05 3:19 
GeneralDrill Down functionality Pin
manojmmj19-May-05 19:05
manojmmj19-May-05 19:05 
GeneralRe: Drill Down functionality Pin
Christian Graus19-May-05 19:21
protectorChristian Graus19-May-05 19:21 
GeneralDatagrid Sort Pin
genius12319-May-05 18:56
genius12319-May-05 18:56 
GeneralRe: Datagrid Sort Pin
Jim Matthews20-May-05 2:57
Jim Matthews20-May-05 2:57 
GeneralNeed help with the listbox Pin
dw192819-May-05 18:53
dw192819-May-05 18:53 
GeneralRe: Need help with the listbox Pin
Christian Graus19-May-05 19:00
protectorChristian Graus19-May-05 19:00 
GeneralRe: Need help with the listbox Pin
Anonymous19-May-05 20:51
Anonymous19-May-05 20:51 
GeneralRe: Need help with the listbox Pin
toxcct20-May-05 3:23
toxcct20-May-05 3:23 
GeneralNeed Help..... Pin
nidhishri19-May-05 18:36
nidhishri19-May-05 18:36 
GeneralRe: Need Help..... Pin
toxcct20-May-05 4:27
toxcct20-May-05 4:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.