accessing word 2003 properties from word 2007 causes error

  • Thread starter charlie.planetxsolutions
  • Start date
C

charlie.planetxsolutions

hi there,

i realize that word 2007 deals with document properties entirely differently.

i have a macro in use that downloads word 2003 documents and based on a
specific document property does some work.

the macro that is saved as a global file in the startup directory does this
fine:

iButton = WordBasic.MsgBox("found '" +
UCase(WordBasic.[LTrim$](WordBasic.[RTrim$](WordBasic.[GetDocumentProperty$]("Title")))) + "'", "Tantalis Document Generator", 0)

but if i copy this macro to a docm or doc file then it throws a 51 'internal
error'.

i'm trying to figure out a way where i can send a client a macro copy with
debug to see why they are having problems. how does one access document
properties of 2003 documents from 2007?
 
J

Jay Freedman

That bit of code looks like it underwent an automated upgrade from
Word 95 or earlier. There's a lot wrong with it from the more modern
VBA standpoint:

- There is no reason to invoke WordBasic for any of the functions
you're using.

- The Trim$() function does in one step the same as the combination of
LTrim$() and RTrim$().

- The GetDocumentProperty$() function has been superseded by the
BuiltInDocumentProperties collection (or the CustomDocumentProperties
collection if it's one that you defined).

- The MsgBox() function has a different order of arguments than the
WordBasic version.

- VBA uses the & character instead of + to concatenate strings. Also,
you can use a space and an underscore at the end of a line as a
continuation character to show that the statement continues onto the
next line.

Try this rewritten statement to see if it solves your problem:

iButton = MsgBox("found '" & _
UCase$(Trim$(ActiveDocument.BuiltInDocumentProperties("Title"))) _
& "'", vbOKOnly , "Tantalis Document Generator")

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
C

charlie.planetxsolutions

thanks jay,

yes, this is ancient code that has not been converted up to vba but has
simply been allowed to be converted by various versions of the office toolset.

your advice fixes this statement for me... but now, of course, the next
statement fails as well:

' Run the autoopen macro associated with this template
WordBasic.Call "CreateDocument.Main"

given the situation, it is advisable to revisit all of the existing code and
re-write to ? what is the upgrade target that would supply the most life to
the logic? vba, vsta...?

thanks again.
 
C

charlie.planetxsolutions

additionally,

i have a number of users that are experiencing problems... while others are
not. if this code is in the startup folder of my office install then it does
not produce errors while if i copy it to a docm then it fails.

is this typical of logic that needs to be upgraded?
 
J

Jay Freedman

thanks jay,

yes, this is ancient code that has not been converted up to vba but has
simply been allowed to be converted by various versions of the office toolset.

your advice fixes this statement for me... but now, of course, the next
statement fails as well:

' Run the autoopen macro associated with this template
WordBasic.Call "CreateDocument.Main"

given the situation, it is advisable to revisit all of the existing code and
re-write to ? what is the upgrade target that would supply the most life to
the logic? vba, vsta...?

thanks again.

I don't know for sure that any rewrite is going to perform correctly
for the next decade or more, the way your old code apparently did. :)

Some time ago I would have said that the size of the installed
corporate base of VBA code would compel Microsoft to ensure backward
compatibility for the foreseeable future. Since the discontinuance of
support for Visual Basic 6.0 without a clear upgrade path to Visual
Basic .NET, though, that compatibility can no longer be taken for
granted.

I have not yet put in the effort to learn VSTA or VSTO, so I'm not
qualified to give an opinion there. Ask in the
microsoft.public.word.programming newsgroup, where you should get a
more useful answer.
 
J

Jay Freedman

additionally,

i have a number of users that are experiencing problems... while others are
not. if this code is in the startup folder of my office install then it does
not produce errors while if i copy it to a docm then it fails.

is this typical of logic that needs to be upgraded?

No, it isn't typical. That sort of thing more often points to code
that makes assumptions about the content and formatting of the
documents it works on, and fails when the assumptions aren't met.

When you say "this code", are you referring to the line about the
Title document property, or the one with the call to Main, or
something else? Exactly what happens when it fails?
 
C

charlie.planetxsolutions

i have users where the code works on some presumably identically configured
workstations and not on others... i have some users where the code fails no
matter what workstation and i have others where the code completes no matter
what workstation.

initially, i am very confused as to why this code works fine in my startup
folder but when i open it as a docm then it fails because of some wordbasic
lines? why could that possibly be?
 

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