Using DDE to communicate with Word 2007

R

Rick

I'm not sure which MS newsgroup to post this in, so I hope it's OK
here.

In another language, I am using DDE to communicate with Word. I
attempt to establish a DDE channel to a Word document on a networked
drive ("P:\MYDIR\MYDOC.DOC") which I use as the 'topicname'. This
code has worked fine for years with Word 2003, but is now failing with
Word 2007.

I came across KnowledgeBase article #970942 that pertains to a June
2009 hotfix to Word 2007 that I think may be relevant. It lists one
of conditions that would be fixed by this HotFix:

"When you use Dynamic Data Exchange (DDE) to communicate with Word
2007, the connection cannot be established if the topic is the file
path of a Word document from a Universal Naming Convention (UNC)
share."

My doc is on a shared network drive, but the topicname I connect to
uses a mapped drive letter rather than a UNC designation. I'm
therefore not sure if this article describes my situation, but maybe
I'm misunderstanding their terminology. I'm not sure what a "UNC
Share" is. Thanks for any help with this situation.
 
P

Peter Jamieson

"When you use Dynamic Data Exchange (DDE) to communicate with Word
2007, the connection cannot be established if the topic is the file
path of a Word document from a Universal Naming Convention (UNC)
share."

It isn't at all clear, is it?
a Universal Naming Convention (UNC)
share."

I don't know for sure, but I suspect they mean a traditional Windows
networking share, i.e. an "SMB" share, rather than (for example) a
shared folder on a SharePoint site, a Distributed File System pathname
or perhaps other things such as a Webdav site and so on.

I did a few simple experiments here using Word 2007 SP2 running on Vista
32-bit. Things may be different on Vista from (say) Win XP because I
believe that the way files on SMB shares has changed and that they are
regarded as coming "from the Internet" and subjected to another set of
security rules.

However, if I create a .doc or .docx, say c:\a\test.docx containing a
piece of text bookmarked as "mybm", open it, and in another document insert

{ DDE WINWORD "c:\\a\\test.docx" mybm }

I do see the bookmarked text. If I insert

{ DDE WINWORD SYSTEM TOPICS }

I see the document names I would expect.

If I then create a share to c:\a - let's say my machine is called MYBOX
and the share is called "a", then if I try

{ DDE WINWORD "\\\\MYBOX\\a\\test.docx" mybm }

Word cannot find the topic. If I close test.docx, then re-open it,
specifically opening up the "network" folders, finding MYBOX, then the
"a" share, then

{ DDE WINWORD "\\\\MYBOX\\a\\test.docx" mybm }

works OK, but

{ DDE WINWORD "c:\\a\\test.docx" mybm }

does not. In other words, Word only responds to the name that was
actually used to open the document. Further tests showed that that
remained true if
a. I assigned a file letter (e.g. Z: to the share). If I open
Z:\test.docx, I have to use

{ DDE WINWORD "z:\\test.docx" mybm }

b. the file is in a folder on another machine altogether.

Unfortunately, on Vista it is either not straightforward or may not be
possible to discover the pathname that Word used to open the document
using DDE, because whenever I opened the file through a share (drive
letter or not),

{ DDE WINWORD SYSTEM TOPICS }

does not display the name of the file that I actually opened - it
displays the name of the copy that Vista (or Word) made in one of my
Temporary Internet folders, e.g.

C:\Users\pjj\AppData\Local\Microsoft\Windows\Temporary Internet
Files\Content.MSO\39CB7BAF.docx

(incidentally, something else I notice is that if I try to update the
DDE field by selecting the field, right-clicking and selecting "Update
field", I always see a dialog saying that the remote data is
inaccessible and do I want to start Winword. The field update only
functions normally if I select the field and press F9).


Peter Jamieson

http://tips.pjmsn.me.uk
 
R

Rick

Thanks for this. I wanted to follow what you're doing but I don't
know what it means to insert "{ DDE WINWORD "c:\\a\\test.docx" mybm }"
into a Word document. How do I do that?

Generally, it sounds like you're reading the sentence "the DDE
connection cannot be established if the topic is the file path of a
Word document from a Universal Naming Convention (UNC) share" to mean
simply that a connection can't be established if the file is on a
regular Window network share. Period. In other words, for our
company, since we are on a regular MS Windows network, it means simply
that a DDE connection cannot be established to a file on the network.
Is that your understanding?

That explanation certainly seems reasonable to me, because if my
topicname is a file on my local hard drive then I have no problem.

If this is the correct reading, then I guess I need to download this
hot fix. Have you downloaded it and gotten good results?

I look forward to your further thoughts.
 
P

Peter Jamieson

{ DDE WINWORD "c:\\a\\test.docx" mybm }

It's a field code.

Click in a blank document, press ctrl-F9 to insert the special "field
code braces {}, then type everything else in the usual way between them.
Then select the field and press F9 to execute it. If you still see the
field /code/ (as above), press alt-F9 to view the field results.

Probably better if you start with

{ DDE WINWORD SYSTEM TOPICS }

which should always return a result. You can use DDEAUTO instead of DDE
to get automatic updates. Probably.
Generally, it sounds like you're reading the sentence "the DDE
connection cannot be established if the topic is the file path of a
Word document from a Universal Naming Convention (UNC) share" to mean
simply that a connection can't be established if the file is on a
regular Window network share. Period. In other words, for our
company, since we are on a regular MS Windows network, it means simply
that a DDE connection cannot be established to a file on the network.
Is that your understanding?

No, the DDE field successfully includes material from Word documents
that Word has opened from traditional network shares. But you have to
know which name was used to open them, and as I said that does not
appear to be possible given that the Topics item may return another file
name altogether. I'd assume that you would get the same info. using any
other DDE method to get the item data, but it is always worth checking.
Perhaps there is another way to find the real file name by issuing
WordBasic via your DDE connection, but it's a while since I last did
that stuff.
If this is the correct reading, then I guess I need to download this
hot fix. Have you downloaded it and gotten good results?

No, I haven't tried it yet. Probably better to try it yourself (I may be
able to have a go later today (friday), but don't hold your breath. :) )

Peter Jamieson

http://tips.pjmsn.me.uk
 
P

Peter Jamieson

If this is the correct reading, then I guess I need to download this
hot fix. Have you downloaded it and gotten good results?

FWIW, I downloaded it (it's quite a large hotfix - over 10Mb) and it
appears to have made absolutely no difference on Vista. All the topic
names are the temporary file names, never "\\server\share" UNC names or
drive: names, if they are accessed over the network. and attempting to
use the "real" name fails. I don't have a Win XP/Word 2007 combination I
can test - perhaps there is a difference in behaviour there, and if that
is the environment you need to test, I think you will have todo that
experiment.

I sometimes wonder whether the MS people are working in a network
environment where everything works rather differently. Otherwise it's
difficult to see why they describe some of the problems the way they do,
and why they think their patches have "fixed" them.

That said, DDE has been "deprecated" for many years and it doesn't
particularly surprise me that DDE-based solutions are beginning to run
into an even more serious set of problems. I suspect someone at your
organisation is going to have to make some hard decisions about what to
do next, both commercially and technically.

Peter Jamieson

http://tips.pjmsn.me.uk
 
R

Rick

OK, I ran the Hotfix and it now works fine on XP. I can now establish
a DDE connection to an opened Word 2007 document that's on the network
by providing its 'real' name in my connection parameter. Without the
hotfix I could only connect to a local file.

But just for an experiment, I did a DDE connect to the 'topics' item
and I get the same result as you -- all it returns to me are the word
'System', three temporary IE files that have nothing to do with Word,
and the name of my 'normal' Word template. It definitely doesn't
return to me the name of my opened Word document. But at this point I
don't need it, as I opened it myself in my other script and have its
name in a variable, and can directly establish a DDE connection to
this document in my script if I give it the name *I* used to open it.
I can do that now even if the file is on the network.

But it sounds that you're saying in your previous message that my
problem was NOT really that the file was on a networked drive but
rather that I have no way of knowing the actual name that Word used to
open the file? I'm a little bit confused on this point -- you're
saying that the name Word uses to open a file may be something other
than its 'real' name (the name I gave it)? What other name could Word
have used?
 
P

Peter Jamieson

1. It looks as if things could be a bit different on XP.

<<
But it sounds that you're saying in your previous message that my
problem was NOT really that the file was on a networked drive but
rather that I have no way of knowing the actual name that Word used to
open the file?
<<
I'm a little bit confused on this point -- you're
saying that the name Word uses to open a file may be something other
than its 'real' name (the name I gave it)? What other name could Word
have used?
2. Well, because I don't know precisely what you were trying to achieve
via DDE, I may have considered scenarious that you do not actually have
to code for. but...

Sure, the file /name/ is the same however it was opened (except that
when Word actually makes a temporary copy then there is another file
name such as 5601AD37.doc), but AFAICS
a. you can only use the filename as the topic name if the file was
opened from a path on a local drive, e.g. c:\mypath\mydoc.doc

b. if the file is on a share, then you have to provide the full
pathname as the topic name. But you can open the same file using two
different pathnames, e.g.
\\myserver\myshare\mydoc.doc
and
z:\mydoc.doc

and you have to use the same pathname that was used to open the file
(even though it's the same filename and file whichever way you open it)

c. if you are using DDE to open the file, you (presumably) already
know the pathname and can use that as the DDE topic name - that's at
least as far as my tests here go. (this may be complicated by changes in
the way Windows/Word have handled UNC pathnames v. mapped drives over
the years, and the one or two registry settings that may affect that
behaviour)

d. it's what happens when you make an assumption about the name of a
file that is supposed to be open that is the potential problem. e.g.
- if you believe \\myserver\myshare\mydoc.doc is supposed to be open,
and in fact the user (say) has opened it, but used the path z:\mydoc.doc
instead, then trying to open the topic using either mydoc.doc or
\\myserver\myshare\mydoc.doc will not work. If you believe only one
document is open, you could get the temporary name from the list of
topics. But how would you know that that is the correct document? And if
multiple documents are open, which temporary name corresponds to the
name you really want? I think you would probably have to use DDE to
access each topic in turn and see if you could discover the "real" name
of the document.

As far as I could see there was no change in this behaviour pre- and
post-fix anyway.

Peter Jamieson

http://tips.pjmsn.me.uk
 
R

Rick

Thanks for this, all of which makes perfect sense.

Except now the plot thickens even more: I uninstalled the Hotfix (Ctrl
Panel, Add/Remove Programs, etc.) just to see what would happen, and
now it's behaving the same way as with the hotfix installed. I can
establish a DDE connection to a file on the network just fine. I
wonder if the hotfix set some registry entries that are NOT undone
when the hotfix is UNinstalled. Oh brother...
 

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