separate code and document

J

Jan Kucera

Hi.
I would like to code some functionality in Word. I also want to have many
documents which use this code (eg. displaying appreciate menu or buttons),
but I don't want to store the code with each of the document. And I need the
word to automatically save these documents (I mean opening a template and
saving it as another document is absolutely not acceptable, it has to open
one document and save the same document).
Any client installation is also not acceptable, for example if the add-in
cannot be packed into the document and must be separately installed by the
client then add-in is also not acceptable.
Any idea?

Thanks, Jan.
 
J

Jezebel

And I want to buy a motor vehicle that has the carrying capacity of a 20
tonne pantech, but which fits into the parking space currently occupied by
my Gogomobile.

You can put code in your documents; or you can put code in a template or
add-in. If you put it in the document (and you're contemplating public or
corporate distribution) it won't get run anyway, because it will get blocked
by security settings. What are you *actually* trying to do?
 
J

Jan Kucera

If it will be signed, it will not be blocked.... or at least I hope.
If I put it into the template... how can ... or just.. how the templates
work?

What I am *actually* trying to do is have a custom menu wich will be loaded
only with my documents. An user opens file, the menu appears, he can edit
the file and save it back to the same location form which he opened it. He
closes, and the menu disappears. I was just afraid if it can be done without
saving the menu code with each document.
 
J

Jonathan West

Jan Kucera said:
If it will be signed, it will not be blocked.... or at least I hope.
If I put it into the template... how can ... or just.. how the templates
work?

What I am *actually* trying to do is have a custom menu wich will be
loaded only with my documents. An user opens file, the menu appears, he
can edit the file and save it back to the same location form which he
opened it. He closes, and the menu disappears. I was just afraid if it can
be done without saving the menu code with each document.

Jan,

Start out by reading these articles. Then if you have further questions,
feel free to come back and ask

Distributing macros to other users
http://www.word.mvps.org/FAQs/MacrosVBA/DistributeMacros.htm


What do Templates and Add-ins store?
http://www.word.mvps.org/FAQs/Customization/WhatTemplatesStore.htm

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
J

Jezebel

Signing on its own doesn't permit anything to run: the user still has to
choose to accept the certificate. And even that won't be enough on a lot of
corporate networks. There are plenty that automatically block *any* document
that contains code, so the users won't receive the document in the first
place.

Your explanation doesn't clarify much. Word's normal behaviour is to save
documents back to wherever they were opened from. What does your code do
that Word doesn't do anyway?
 
J

Jan Kucera

Just quick answers before reading the Jonathan's tutorial:
Actually if user choose not to accept certificate it's his problem, I'm not
trying to force the code to run in each case.
Secondly, I'm not going to send anything. The documents are going to be
downloaded from HTTP server.

Okay, I will try to summarize the steps I need, perhaps it helps. I have no
idea about the solution I should choose yet.

1) User opens a document over HTTP.
2) When the document is open, some menus are to be added.
3) User do some stuff and closes/saves the document back.
4) The menu, which has sense only with my documents is to be removed.

Requirement: Do not install anything at the client side.

So, I generally see this ways:
* Include code in each document.
- bad for maintenance of the code
- bad for storage, lot of documents
- bad if user chooses to send the document to another user, which should
not use this
* Put the code into the template.
- a "new" document is created when openning template, cannot be saved back
- a link to the template over HTTP from the documents would be nice,
however it is not possible if the template is not added to the word manually
* Make an add-in
- as far as I know must be installed
- bad maintanance
- a link to the addin over HTTP would be the thing I need, but it is not
possible
* Get the document from the db, put code, send it to the user, get it from
the user, remove code and save it.
- Office on server side are strongly not supported
* Create the Word as ActiveX in the explorer and do the stuff externally
- That's the most probably scenario I am afraid I would have to end with,
but I juste hate client scripting.

So.. thats all I know at the moment.
 
J

Jan Kucera

Hi Jonathan.
Thank you for your links, I find useful to read through them.

So... my questions are:
1) Can I attach a document to the template over HTTP?
2) Can I do this temporarily eg. not saving it with the file?

So.. I can put into Document_OnLoad a code which downloads the template,
saves it to the templates folder and loads/attaches document to it? And then
on Document_Close just detach the template, perhaps delete it...

Feel free to see my thoughts about solutions in reply to Jezebel.
Thanks, Jan.
 
J

Jonathan West

I suspect that what you are trying to do is impossible. See inline...


Jan Kucera said:
Just quick answers before reading the Jonathan's tutorial:
Actually if user choose not to accept certificate it's his problem, I'm
not trying to force the code to run in each case.
Secondly, I'm not going to send anything. The documents are going to be
downloaded from HTTP server.

Okay, I will try to summarize the steps I need, perhaps it helps. I have
no idea about the solution I should choose yet.

1) User opens a document over HTTP.

When the document is open, it isn't the document on your web server which is
opened. What actually happens is that a copy of the document is downloaded
to the user's Temp folder, and that local copy is opened in Word.
2) When the document is open, some menus are to be added.

That requires some code. Now, if you are making an application used by the
general public, then this code will have to be in the document itself,
because nothing else will be downloaded.

If you are working in a corporate environment, then you can perhaps get a
template or add-in distributed that does the necessary. By the way, do you
have copies of every version of Word back to Word 97 available for testing?
Because that is the range of versions that you will meet with a web site
available to the general public.

3) User do some stuff and closes/saves the document back.

Saves the document back where? To the local temp folder, which is all that
Word knows of, or to the HTTP server? If the latter, then you need separate
code which knows the server details to handle the file upload.
4) The menu, which has sense only with my documents is to be removed.

if you use code to create menus, make very sure that everything is cleaned
up after you, otherwise you will have a lot of unhappy customers. Read up
carefully on the CustomizationContext property and make sure you test
extremely thoroughly.
Requirement: Do not install anything at the client side.

That last bit is what almost certainly makes this impossible.
 
J

Jan Kucera

When the document is open, it isn't the document on your web server which
is opened. What actually happens is that a copy of the document is
downloaded to the user's Temp folder, and that local copy is opened in
Word.

Saves the document back where? To the local temp folder, which is all that
Word knows of, or to the HTTP server? If the latter, then you need
separate code which knows the server details to handle the file upload.

Well actually the file is on DAV-compilant server, so correct opening and
saving is handled.
That requires some code. Now, if you are making an application used by the
general public, then this code will have to be in the document itself,
because nothing else will be downloaded.

If you are working in a corporate environment, then you can perhaps get a
template or add-in distributed that does the necessary. By the way, do you
have copies of every version of Word back to Word 97 available for
testing? Because that is the range of versions that you will meet with a
web site available to the general public.

My environment... is somewhere in the middle. At first it is not general
public. However it also isn't my corporate. Let's say the files will be
distributed to corporates servers for theirs internal use - so I have no
control over the network, login scripts and so on.

And nope. Working in 2003 at the moment, since the built-in of xml in
managed code (the menu structure will be loaded from remote xml). However I
am thinking about writing it in VBA to get compatibility downto 2000, but if
the overhead is too big, then it will just run in 2003.


Please Jonathan let me know if it would be possible as I replied to you, to
include a code in the document open event to download the template, store it
into the templates folder and attach to it. Thanks.
 
J

Jonathan West

Jan Kucera said:
Hi Jonathan.
Thank you for your links, I find useful to read through them.

So... my questions are:
1) Can I attach a document to the template over HTTP?
No.

2) Can I do this temporarily eg. not saving it with the file?

No. Not temporarily, permanently or any other way.
So.. I can put into Document_OnLoad a code which downloads the template,
saves it to the templates folder and loads/attaches document to it? And
then on Document_Close just detach the template, perhaps delete it...

Hmmm. Do you have VBA code that can download using HTTP without making use
of external DLLs? I don't. At least, not that will work will all the
versions of Windows (and MACOS) out there. That would be your first
requirement for this.
Feel free to see my thoughts about solutions in reply to Jezebel.

Why so you want to modify the menus anyway?


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
J

Jan Kucera

Yes, I was thinking at least about urlmon ... Using DLLs is not possible in
VBA?
(oh and in managed there is built in support for opening stream from http I
think)

Menus - to include linked data to the document. The structure of the menu
has to reflect structure of the data.

Anyway, thank you for all responses, it is fine to have somebody trying to
help you. ;-)
 
C

Cindy M -WordMVP-

Hi Jan,
And nope. Working in 2003 at the moment, since the built-in of xml in
managed code (the menu structure will be loaded from remote xml). However I
am thinking about writing it in VBA to get compatibility downto 2000, but if
the overhead is too big, then it will just run in 2003.
In this scenario, it would be possible to use a TRANSFORM to put the code you
need, including any toolbars, into the document before it downloads. The only
caveat might be including a digital signature, as transformed file would have
to be signed, not the original.

This would limit you to Word 2003 and higher, at least until the release of
Office 2007. There should be a conversion filter available at the at time that
will allow Word 2000 and 2002 to open Word 2007 XML files.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
J

Jan Kucera

Hi Cindy, nice to hear from you again.. ;-)

So you advise me to transform the code on the server side into the document
before sending and "untransform" :] it back during save...? And if I'm
right, I have to use Word XML 2003 format...?

Jan.
 
C

Cindy M -WordMVP-

Hi Jan,
So you advise me to transform the code on the server side into the document
before sending and "untransform" :] it back during save...? And if I'm
right, I have to use Word XML 2003 format...?
That would be a possibility (don't know whether you'd have to transform again
when pulling it back, though...)

For the moment, this would limit you to Word 2003 and its XML format, yes. But
you should look on microsoft.com for the publicly available information
concerning Office 2007 and its open XML formats. As I mentioned, this will
include a conversion filter that anyone using Word 2000 and later can install.
The conversion filter will let everyone open and save in Office 2007 file
format (XML).

Another possibility, if you need to realize this sooner and still want to
support older versions, would be to transform the Word 2003 XML to Word's HTML
format, or to RTF. Both are "round-trip", and so support including macros and
toolbars in the file. As long as you're careful to not use any structures that
were introduced after Word 2002, that should work fine.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
J

Jan Kucera

Hi Cindy.
In fact I need to store the document code-free (really this should be more
template than code-behind), so I need to clear the document before save -
unless there is a way how to include a code into a document, which will not
save with it (also if the user chooses to mail the document to somebody then
without the code).
The filter for 2007 is fine and believe I am looking for the public beta
every day. However I have the limit of not installing anything on the
client's computer, if you remember. But I read that 2007 can run at the
server side without problems so I could make this on the serer side.
But using RTF or HTML is also good idea (although I find the Word's html
quite messy :)). Do you know about any tutorial of these formats and
including macros in them?

Thanks,
Jan

Cindy M -WordMVP- said:
Hi Jan,
So you advise me to transform the code on the server side into the
document
before sending and "untransform" :] it back during save...? And if I'm
right, I have to use Word XML 2003 format...?
That would be a possibility (don't know whether you'd have to transform
again
when pulling it back, though...)

For the moment, this would limit you to Word 2003 and its XML format, yes.
But
you should look on microsoft.com for the publicly available information
concerning Office 2007 and its open XML formats. As I mentioned, this will
include a conversion filter that anyone using Word 2000 and later can
install.
The conversion filter will let everyone open and save in Office 2007 file
format (XML).

Another possibility, if you need to realize this sooner and still want to
support older versions, would be to transform the Word 2003 XML to Word's
HTML
format, or to RTF. Both are "round-trip", and so support including macros
and
toolbars in the file. As long as you're careful to not use any structures
that
were introduced after Word 2002, that should work fine.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister


This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
C

Cindy M -WordMVP-

Hi Jan,
In fact I need to store the document code-free (really this should be more
template than code-behind), so I need to clear the document before save -
unless there is a way how to include a code into a document, which will not
save with it (also if the user chooses to mail the document to somebody then
without the code).
The filter for 2007 is fine and believe I am looking for the public beta
every day. However I have the limit of not installing anything on the
client's computer, if you remember. But I read that 2007 can run at the
server side without problems so I could make this on the serer side.
But using RTF or HTML is also good idea (although I find the Word's html
quite messy :)). Do you know about any tutorial of these formats and
including macros in them?
No tutorial, no. Specs on the RTF format are on Microsoft.com, but I've never
been able to find any documentation on the HTML format. Best, usually, is to
save simple document in the format that interests you and do some sleuthing.

In my experience, the macro stuff is usually saved in a separate "block", in
any of the three formats. So it wouldn't be difficult to strip it out when a
file comes back to you. Someone choosing to email the document to a
third-party, though... No way you can "clean" the document up so that it
doesn't trigger macro security, I'm afraid, short of having a macro in the
document that essentially transfers the content to a NEW document. Then the
user could email the copy.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
J

Jan Kucera

Hi,
just to say either RTF nor HTML supports macros embedding (Word says during
save). :(

What a pitty, moving to XML - have to use 2003 only...

Jan
 
J

Jan Kucera

Uh, the macros are binary encoded in the XML.... anybody know how to put
them inside on the fly?
 

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