Declarations

T

Tom

Advice on the following would be appreciated:

We use Microsost Office 2003. From an Microsoft Access database, using vba,
we export a memo field to a word document and save in HTML format. Within
our Access database we reference Word 11.0 Object library.

What is causing a problem is that some pc's using that datatbase are using
Office 2002 with Word 10.00 Object library. What we would like to do is to
be able to reference our code irrespective of which Word object library is
used and also how do we reference wdFormatHTML and wdDoNotSaveChanges.

Thanks in advance

Tom
 
M

Malcolm Smith

Tom

What you ought to do is to investigate Late Binding. Using the references
is Early Binding and the drawback is what you have found; it depends on
the exact version of the code.

With Late Binding you just have an Object variable (i.e. a pointer), so
where you would have had:

Dim oAccess as Access.Application

you would now have

Dim oAccess as Object


And to create the object you would do something like:

Set oAccess = CreateObject ("Access.Application")

You'd have to check the syntax on this function but you get the drift. I
usually get the syntax mixed up between CreateObject() and the very
similar GetObject().

What happens is that at runtime the Library "Access" is known to your
machine as it will be in the registry and the "Application" is the object
within that library.

With late binding the application gets the right information from the
registry, finds whatever it needs to find and then creates the object.

Changing from early binding is very simple. Generally it's just a matter
of changing the variable type, removing the reference and the changing the
New statement to a CreateObject() function.

I tend to use early binding for development and then turn to late binding
if I have to send the code out to people.

Hope that this gets you on the right road. Honestly, it's so easy.

- Malc
www.dragondrop.com
 
T

Tom

Hi Malcolm

Will try your suggestions.

Can you clarify we would declare wdFormatHTML and wdDoNotSaveChanges

TIA
Tom
 
M

Malcolm Smith

Tom

Yes, you will have to put in your own CONST statements to replace the
instrinc variables. Sorry, forgot about those.

- Malc
 
T

Tom

Malcolm

Can please you give me an example of appropriate CONST statements for those
2 references.

Tom
 
M

Malcolm Smith

Sub TomExample_EarlyBinding()

Dim oWord As Word.Application
Dim oDoc As Word.Document


Set oWord = New Word.Application
Set oDoc = oWord.Documents.Add

oWord.Selection.TypeText "This is early binding with Office 11"
oDoc.SaveAs "C:\TomExampleEarlyBinding.htm", wdFormatHTML
oDoc.Close wdDoNotSaveChanges

Set oDoc = Nothing
Set oWord = Nothing

End Sub


Sub TomExample_LateBinding()

Dim oWord As Object
Dim oDoc As Object


Const MKS_wdDoNotSaveChanges As Long = 0
Const MKS_wdFormatHTML As Long = 8

Set oWord = CreateObject("Word.Application")
Set oDoc = oWord.Documents.Add

oWord.Selection.TypeText "This is late binding with Office x"
oDoc.SaveAs "C:\TomExampleLateBinding.htm", MKS_wdFormatHTML
oDoc.Close MKS_wdDoNotSaveChanges

Set oDoc = Nothing
Set oWord = Nothing

End Sub


To get the value of the statements; before I pulled the plug on the
reference to the Office application, I went to the immediate window and
typed:

?wdDoNotSaveChanges
0

?wdFormatHTML
8

and I would do that for all of the instrinsics used.


I hope that this helps.

- Malc
www.dragondrop.com
 
M

Malcolm Smith

Tom

You are most welcome. Good luck with the conversion and if you have any
problems then please do shout.

- Malc
 

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

Top