how to find that date macro is enabled before opening document.

O

om_chandan

could any one tell me the way to find out an enabled macro(let's take
the case of date)in the footer of a document before opening the
document.
actually the problem statement is like this:
I have millions of office document and I want to select only those
document which has date of creation at their footer it means the date
macro for those document are enabled,and now I want to open only those
document which meets my filtering criteria.
I want to know how this could be done programmatically.

chandan.
(e-mail address removed)
 
P

Paul Berkowitz

could any one tell me the way to find out an enabled macro(let's take
the case of date)in the footer of a document before opening the
document.
actually the problem statement is like this:
I have millions of office document and I want to select only those
document which has date of creation at their footer it means the date
macro for those document are enabled,and now I want to open only those
document which meets my filtering criteria.
I want to know how this could be done programmatically.

Any programmatic means (VBA or AppleScript) will have to open the documents
to find out. They can only find out information about headers, footers, or
indeed anything whatsoever about the document content and format by opening
them and doing the work within Word itself. There's nothing that the file in
the Finder can say about it. Then the script or macro could close them
again, of course, but you'd have loads of documents opening and closing
again, flapping away, while it does the filtering. Alternatively, why don't
you just add an unusual character(s), like ¶ (option 7) to the name of every
document which meets those filtering criteria. Then an AppleScript could do
it easily just looking at the names of the files, and then open just those.
(Or you could too.)

--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
R

Russs

Chandan, see within text
A Tiger Spotlight search on the Mac can find documents that have the
specific field code word CREATEDATE in them, if all you want to know is
which documents are already set with fields to show a document creation
date.
Otherwise you have to use another type of file search program that can
search within the contents of files, not just a search within the filenames.
Like http://www.geditcom.com/grepArtee/index.html for the Mac or
http://www.powergrep.com/ for the Windows PC.
 
J

John McGhie [MVP - Word and Word Macintosh]

Chandan:

I need to find out what you are really interested in?

* The creation date of the document?

* The date that may appear in the footer of a document?

* Or a document that has the CREATEDATE field in its footer?

Let me explain...

The date upon which each document was created is a property stored in the
file system header and in the document properties. These are binary dates:
and can be quite different. The file system creation date is the date upon
which the file was written to disk. The document creation date is the date
the original document was created: it will be copied if the original
document is copied, so can be years different from the file creation date.

The author of a document may choose to write a date in the footer. Or may
not. If s/he doesn't put a date there, there will be no date in the footer.

If the user does put a date in the footer, they may type it, or insert one
of the three date fields Word provides. These are the CREATEDATE, the
SAVEDATE and the PRINTDATE. Each of these are two 16-bit integers, one
representing a Julian date, the other a time of day. Each of these fields
replicates information from the Properties store in the document. You do
not need to read the footer to get to it: you can read the date concerned
directly from the document properties.

If you want to find only documents that have a create date in a footer, you
will have to open the document in Word to do that. There are three footers
per section, and an unlimited number of sections per document.

There could, of course, be macros that write dates into any nominated place
in a document. These macros may be in the document, but usually won't be:
they would be in the attached template.

Manipulating dates with "Macros" is advanced Word usage. I would not expect
to find this happening in corporate documents without it being documented
somewhere, along with a way to access the result. So I think it very
unlikely that you are looking for documents with "macros" in them.

The usual way of adding dates to documents is with "Fields". Different
thing. Look them up in the Word Help. Reading either the field or its
result from a Word document is a huge programming task unless you are
actually using Word to do it. In the binary file, a field is simply a
pointer that indicates an offset in the file where the information can be
found. But any field can be nested within other fields which
computationally alter the result.

The problem is too hard: you would have to do a very large amount of coding
to resolve this without using Word. I suggest that you either filter on the
file system dates, or open the document in Word and read the field results.

Hope this helps

could any one tell me the way to find out an enabled macro(let's take
the case of date)in the footer of a document before opening the
document.
actually the problem statement is like this:
I have millions of office document and I want to select only those
document which has date of creation at their footer it means the date
macro for those document are enabled,and now I want to open only those
document which meets my filtering criteria.
I want to know how this could be done programmatically.

chandan.
(e-mail address removed)

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 4 1209 1410
 
O

om_chandan

Hi John,

First of all thanks for the descriptive answer.
Actually the problem which I am facing at present that I do know how
the customer(whose data my company product will be processing) has
created an office document.s/he may have inserted date either as a
field or by enabling a macro.
All I have to implement a superset of logic programatically which could
find the presence of file creation date in the footer of document.

thanks
(e-mail address removed).
 
J

John McGhie [MVP - Word and Word Macintosh]

OK...

1) Assume it is NOT a macro. It would be very rare for a user to use a
macro for dates. An extremely sophisticated user might if they needed to
perform complex date arithmetic.

For most purposes, you do not need macros to do dates in Word, so assume
they didn't use one.

2) If they used fields, the fields are reading the file creation date from
the file header of the document. That date may be replicated all over the
document structure, but the source is the timestamp written by the system
into the file header when the file was written to disk.

The system time-stamp just happens to be the easy one to read: you can get
any number of utilities to return that.

Word also writes some dates into its file properties. These dates are
somewhat unreliable (you can never be sure what the date refers to: it can
be the document the user copied to make the document you are now looking at,
or its template).

It is also a huge programming job to return "anything" from a Word document.

You haven't had a look in a Word file yet, have you? :) Hint: It's not
"text". It's compressed binary, containing binary pointer-referenced
delimiter-terminated objects, of which dates are some of the properties of
some classes of objects.

You end up almost writing your own version of Microsoft Word in order to
have an application that can reliably find objects in the binary file
format. Once you can deconstruct the document into its component objects,
you then have a relatively simple job of inspecting the footers (each
document can have unlimited numbers of sections, and each section can have 0
to 3 footers). If you find a footer, and you find a field in that footer,
and the field contains text, and the text represents a date, how can you be
sure that that's the date you wanted. Knowing Word users as I do, chances
are the date they "meant" is typed in normal text at the bottom of the page,
outside the footer structure altogether :)

Of the several dates you will find in some documents, which one is the one
the user "meant"??

Stick with the file system time stamp, or you WILL go mad :)

Cheers

Hi John,

First of all thanks for the descriptive answer.
Actually the problem which I am facing at present that I do know how
the customer(whose data my company product will be processing) has
created an office document.s/he may have inserted date either as a
field or by enabling a macro.
All I have to implement a superset of logic programatically which could
find the presence of file creation date in the footer of document.

thanks
(e-mail address removed).

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 4 1209 1410
 
O

om_chandan

Hi Russ,
Thanks for the reply,could you please tell me that is there any VBA
module
as open source which can trace the footer(with the creation date of
file) or I have to create one.
thanks
(e-mail address removed)
 
O

om_chandan

I agree with all point,but the solution is still missing.well, suppose
there are two circumstances:
(1.) The person creating a document is a technical person and prefers
to use macro and he is using it to insert creation date of file at its
footer,and after few months he gives me those documents and ask me to
tell him separate the documents on the creation date mark.
(2.) About the second opion as you also told that creation date and
other properties are present in file system header.

Actually I have written a perl script but it is giving me the
properties like author's name etc but not the date(which i had inserted
while creating document).
I have to know it programatically as I have loads of document(I can
compromise on the time taken in processing) and without opening it.
regards
chandan
 
O

om_chandan

Hi There,

see to it


Actually I am not changing the problem statement and even if this is
the case then let me put it again:


Problem statement:-


Is there is a way to check the presence of a macro in an office
document.
This is the macro if enabled, shows today's
date(if it was a date macro) in the footer of the document. Once I
could find a way to do this,I can execute it on a data share to
identify all such documents.
Once the mechanism is in place, then one can
execute it on a listing of all the files in the data share and get the
output.


This is the exact problem statement and if you could guide me to get an

answer then it will be really good.


Thanks
chandan
 
D

Daiya Mitchell

You'll need to clarify again.

FIRST, what version of Word and Operating System are you running?

However, the way you are conceiving of the problem is not appropriate.

Particular macros aren't really enabled in a doc, and macros don't need to
be in a doc to be used. Macros run, and then a result shows up in the doc.
I think your only approach would be to search for the result in the text of
the doc. I don't think there's a flag anywhere saying "Macro X ran on this
doc." For your example, a CreateDate field in the footer, it doesn't make a
difference to Word how that CreateDate field got there, whether a macro
inserted it or the field was typed or the field was entered via a toolbar.
The "how" of creation is not recorded. All you would be able to search for
would be a CreateDate field in the footer, regardless of the method used.

Certain results will be part of the metadata held outside the document, and
would be easier to get at.

Depending on the size of the documents, as stated before, Spotlight might
find the result in the document, if you are using Tiger as your OS.

If the result doesn't show up in Spotlight's index, the only way to find it
is going to be to open up each document. An applescript can certainly loop
through an entire folder, opening each document and searching for the
designated text, and probably if it finds it, moving that doc to a different
folder.

What's your prejudice against opening the document to get what you need?

When you say "get the output", what are you hoping to get? Can you explain
why you need to do this in the first place?
 
O

om_chandan

Hi Daiya,

I understand that it is not fesible to find out whether a macro is
enabled or not in a doc file without opening it.

But there should be some entry in this doc file regarding this macro.
Otherwise what will be the difference between two same doc files, one
having a macro enabled and the other one without any macro.

In the 1st case, as soon as we open the document the macro gets
executed. That means something is done internally so that this macro
gets executed.

It is a possiblity that the MS people have not exposed any
functionality to get such things like : given a macro name, can we
findout whether it is there or not in the document. Or list out all the
macros in the doc file etc..

And finding the current date from the footer/header is not an easy
solution. There are so many date formats available. People use
different formats. So it'll be an expensive operation to open a
docuemnt, parse it, comapare with the present date in different date
formats, close the document. We handle thousands of documents. So it
may not be a feasible solution.

BTW we use Win2000, Win2003 servers as our OS.
The word documents can be of any version: office-95, office-97,
office-2000, office-xp, office-2003.

I think I am clear in my questions. Or please let me know, I'll
elaborate more.

WR,
-Chandan
 
D

Daiya Mitchell

Hi Chandan,

When you say a macro runs when you open the doc--and previously you said
This is the macro if enabled, shows today's
date(if it was a date macro) in the footer of the document.
do you mean that when you open the doc the date in the footer changes to
today's, and you want to figure out which of those documents will do that?
Because that's not a macro.

The keyboard shortcut for Insert Date, and the icon on the header/footer
toolbar insert an automatically updating date field, {DATE}, so if either of
those were used in creating the doc, you get date changes when the doc is
reopened.

To fix old docs, select the field, toggle field codes on the right-click
menu (or hit alt-F9), and change the DATE field to CREATEDATE.

You need to open up a few of these documents and check whether that is the
solution.

For more information, see here:
http://word.mvps.org/FAQs/TblsFldsFms/DateFields.htm

Even if that isn't exactly it, what you think is a macro might be a field
updating, so be sure to check, using Alt-F9 to see field codes. It's much
more likely that a field is updating than it is that this company stored a
macro in each of thousands of documents.

Regardless, whether that is or isn't the problem, I had a feeling you
weren't on a Mac....you've been asking on a MacWord group. That's why
people keep mentioning AppleScript and Spotlight. You need to go ask on a
VBA group. For Windows, you might have more access to some of the document
properties without opening, and their VBA is different.

If the field code is the problem, the date parsing thing is easier, because
you only need to look for the field code, which will be { DATE } or { TIME
}, though possibly with some modifiers, e.g. { TIME \@ "d-MMM-yy" }. But you
get a {Time} field when people used Insert | Date and Time set to
automatically update, so it's much more likely to be a {Date} field, which
can be created accidentally. Ask the VBA people how you would automate the
process I stated above, of changing {Date} to {CreateDate}, once you've
confirmed that's what you need.

If it really is a macro, a macro that runs on opening is only going to have
a couple possible names, one of which would be AutoOpen.

Ask them whether there is a way to tell if a document has an AutoOpen or
similar macro stored in it. Your last post is the only one that has made it
very clear what you need, so repeat some of that, and be sure to state
versions. You might be able to get at those documents with macros that
execute on opening, I don't know whether VBA has hooks to return information
on VBA itself, though I'd imagine pulling a list of macros in the doc should
be possible.

However, I would say that rather than ask theoretical questions on the group
(as you did here), you need to sit down with a few of the problem documents,
develop a manual way to fix the problem, and then ask how to automate that
manual way, being sure to explain the context for why you need to automate
it. That way you'll be sure to get *something* useful, and if anyone can
think of a shortcut around your manual method, they'll probably share.

http://groups.google.com/group/microsoft.public.word.vba.general

Hope that helps,
Daiya
 
J

John McGhie [MVP - Word and Word Macintosh]

Hi Chandan:

But there should be some entry in this doc file regarding this macro.
Otherwise what will be the difference between two same doc files, one
having a macro enabled and the other one without any macro.

There is none. That was Daiya's point :) A macro can write anything it
likes anywhere in the document, but it leaves no trace at all that whatever
data item it inserted was written by a macro.

Chances are, this particular macro is writing a text string into the footer.
You would need to parse all of the footers in all of the documents looking
for strings of text.

You will then need to determine whether those strings are (or might be...)
dates.
In the 1st case, as soon as we open the document the macro gets
executed. That means something is done internally so that this macro
gets executed.

Possible. It's more likely that the function is a FIELD, not a Macro. If
it is the common user-inserted field named DATE, this is updated on document
open each time.

If it is a macro, the Macro is in the Normal template, ot the attached
template, or a loaded Add-in, and it is named AutoOpen() or AutoExec() or
AutoNew()
It is a possiblity that the MS people have not exposed any
functionality to get such things like : given a macro name, can we
findout whether it is there or not in the document. Or list out all the
macros in the doc file etc..

Yes, you can, but not without opening the document. Once you open the
document, you can enumerate the VBA collection looking for macros. You can
open a document with Macros disabled, but if you do, you then can't
enumerate the macros collection.
And finding the current date from the footer/header is not an easy
solution. There are so many date formats available. People use
different formats. So it'll be an expensive operation to open a
docuemnt, parse it, comapare with the present date in different date
formats, close the document. We handle thousands of documents. So it
may not be a feasible solution.

I don't hink it is, if the date is written into the footer as a string, and
I suspect very strongly that it is.
BTW we use Win2000, Win2003 servers as our OS.
The word documents can be of any version: office-95, office-97,
office-2000, office-xp, office-2003.

Ahhhh... OK, investigate DSOFile.dll...

http://www.word.mvps.org/faqs/macrosvba/DSOFile.htm

You will need to run Windows Word on the server to use it, but that ActiveX
..dll will read document properties for you without opening the document.

Cheers
I think I am clear in my questions. Or please let me know, I'll
elaborate more.

WR,
-Chandan

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 4 1209 1410
 

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