Frank Pasztor

greetings,

I've installed the SDK on my system and can access it from Visual Studio. But I can't access it from VBA. I've updated Windows and Office 2007 and have whats required but when i look at the references dialog in Word 2007s VBE there's no listing for 'Microsoft.Office.DocumentFormat.OpenXml ' and when I use browse to locate the dll manually i get a message that the file cannot be referenced.

I'm totally lost...help...



Re: Microsoft SDK for Open XML Formats cannot reference sdk from Word VBA

MauricioG

Hi Frank, yes: you can't but....

VBA is COM based and the SDK is a .Net tool and for interoperate com<==>net is necessary an Interop tool (another wrapper, yes) that do the job of translate into both protocols.

When you - working with Visual Studio - generate a .Net dll (different to a COM dll like - as an example - any MSXML ) can go to the VS IDE and tell it to prepare your dll for Interop.

It seems not to be the case of the SDK, but....you can create your own .Net library who (yes) fully uses all the SDK and compile it for Interop and...reference it from VBA.

Do you know how to register your library for COM Interop (it's only a check into the VS IDE)






Re: Microsoft SDK for Open XML Formats cannot reference sdk from Word VBA

Frank Pasztor

Thanks for the reply but no I don't. I think that I'll have even more reading to do!





Re: Microsoft SDK for Open XML Formats cannot reference sdk from Word VBA

MauricioG

Which is the .Net Framework language you are working on (VB, C# )






Re: Microsoft SDK for Open XML Formats cannot reference sdk from Word VBA

Frank Pasztor

Up to now I've been working in VBA so I've moved over to VB. I'm using the VS 2008 beta.





Re: Microsoft SDK for Open XML Formats cannot reference sdk from Word VBA

MauricioG

I didn't look up where it is into VS2008 and I haven't one near to me but I'l tell you where is it in VS2005.

Project Properties ==> Compile ==> Register for COM Interop (checkbox)

Tell me if you find it please.






Re: Microsoft SDK for Open XML Formats cannot reference sdk from Word VBA

Frank Pasztor

Great you where right on the money. I do have another question though.

In the SDKs help it has several examples of using the WordprocessingDocument. But in all of them they use Open.

for example:

Dim wordDoc As WordprocessingDocument = WordprocessingDocument.Open(document, False)

What I want to do is retrieve and process customXML from within the open document. The only way i could use these examples would be to create a copy of the document I'm working in and save it so that I could then open the copy using WordprocessingDocument.Open

Can I use the SDK to work in the 'active document' or do I have to create a copy





Re: Microsoft SDK for Open XML Formats cannot reference sdk from Word VBA

MauricioG

  1. WordprocessingDocument.Open(document, True)
  2. There is a sample in the SDK doing what you want using a StreamWriter in Excel, is this what you need

' How to: Insert a CustomXMLPart part.
Public Sub XLInsertCustomXml(ByVal fileName As String, ByVal customXML As String)
Dim xlPackage As SpreadsheetDocument = SpreadsheetDocument.Open(fileName, True)
Using (xlPackage)
' Add a new custom XML part.
Dim workbookPart As WorkbookPart = xlPackage.WorkbookPart
Dim xmlPart As CustomXmlPart = workbookPart.AddNewPart(Of CustomXmlPart)()
' Copy the XML into the new part...
Dim outputStream As Stream = xmlPart.GetStream
Dim ts As StreamWriter = New StreamWriter(outputStream)
Using (ts)
ts.Write(customXML)
End Using
End Using
End Sub






Re: Microsoft SDK for Open XML Formats cannot reference sdk from Word VBA

Frank Pasztor

I apologise for the confused nature of my questions. I've found myself haveing to move from supporting Word 2003 VBA directly to OpenXML/VS 2008. It would be easier to explain where i'm coming from.

Currently i support a large number of Word 2003 templates written in VBA. Many of them hold closely related information which differs depending on the section/department/date. This info is stored in EXTERNAL INI and text files.

The way it works is this;

The user creates a new document and a userform asks for information(metadata) which is saved as properties/variables in the new document.

The new documents VBA then processes this information updating fieds, inserting AutoText etc.

In some cases there are large sections of formal text etc, these are stored in INI or text files at a central location.

The VBA opens and reads the required file and processes the text, and then updates the new documents boilerplate text.

I can do that now in W2007 using "Globals.ThisDocument.CustomXMLParts" to process CustomXML that now contains this information( which used to be in INI files). But I'm still processing it as if it was text.

The best way for me to get to grips with OpenXML is to experiment with it and find out what I can do with it. my main hurdle is that the "WordprocessingDocument" examples all assume that the XML is in another external closed document.

What I need to do is process CustomXML internally in the ActiveDocument that is running the code.

Though the INI/W2003 method is similar to the "WordprocessingDocument.Open" situation, I can see advantages to replacing some of the more general/global elements that I used to use AutoText for with CustomXML.





Re: Microsoft SDK for Open XML Formats cannot reference sdk from Word VBA

MauricioG

Hi Frank Smile

Your question is truely and really interesting.

It's a matter of technologies and architecture.

Would you close the thread and create a new one around this interest

I suggest you something around VBA & Open XML.

The use of both technologies, one or the another it's something to talk about, no doubt.






Re: Microsoft SDK for Open XML Formats cannot reference sdk from Word VBA

wope

Hi Mauricio,

very interesting.
But in the "Getting Started" description http://msdn2.microsoft.com/en-us/library/bb456488.aspx
says the following:

To add a reference in a Visual Basic for Applications project

In the Visual Basic Editor:

  1. On the Tools menu, click References.

  2. In the References dialog box, scroll to the Microsoft.Office.DocumentFormat.OpenXml option, click to select it, and then click OK.


So for rapid developing I don't like to install the whole VS 2005.
Is there any download link for such dll

THX

Peter (wope)




Re: Microsoft SDK for Open XML Formats cannot reference sdk from Word VBA

MauricioG

I don't know Peter (I didn't test this error but I must believe in you and Frank ) but: if you are working with Word VBA there's a Winword process in your PC memory and you have your bill paid.

You have Microsoft Word, it's weighting with all its process power and Object Model.

Why should you call the standard lightweight package oriented Open XML libraries






Re: Microsoft SDK for Open XML Formats cannot reference sdk from Word VBA

Frank Pasztor

I can well understand your question. Though the new Word 2007 formats make some things easier and hold a lot of potential benefits other things that are easy in VBA (such as keybinding) are horribly differcult in VSTO.

We have a large number of Word 2003 templates written in VBA and I am tasked with converting them to VSTO and investigating ways to add value to the templates. For me its not a question of whether I can make logically structured authoring templates using VBA, its moving our system to OpenXML and VSTO.

My learning curve is pretty steep as it is without being blind sided by the SDK. The help file says its easy to reference OpenXML in VBA and I assumed my lack of knowledge with VSTO and OpenXML meant that I missed some simple step hence this thread. Either the help file is wrong or the dll I downloaded is bad, how do I tell which it is and what can I do about it





Re: Microsoft SDK for Open XML Formats cannot reference sdk from Word VBA

MauricioG

I think the best way to generate templates is Open XML because the nature of the package make the modules natural (styles, spreadsheets, images and so on) to create and manage.

These modules can be combined with great flexibility.