Macros

T

Tim.Craig

I have two problems that that I need help solving.

1. I have two documents with macros. The first document
attaches the second document - wich I have working
correctly. The problem is that the macro in the second
document does not remain available when I attach the
document to the first. How do I fix this problem??

2. The second document is basicly filled with a two
column table in the last row and column is a macro that
contatinates a new line to the end of the page for as many
times as the user needs. How do I add the macro to each
new line as it is added???

If anyone can help I would be extremely grateful.

Tim Craig
 
J

Jay Freedman

Hi Tim,

One or both of us is mightily confused. It may be just a matter of
terminology, but somehow I don't think so...

1. Exactly what are you doing to "attach" the second document to the first?
In Word and VBA, the only meaning of "attach" that sounds similar to your
task is setting a new value for the ActiveDocument.AttachTemplate property.
But this doesn't put any text (or tables or whatever) into an existing
document, it just makes things like macros and AutoText entries available.
So I suspect you're using something else, such as Selection.InsertFile. That
does insert text from the second file, but it doesn't bring in any macros.

I suspect that what you really want is this: Resave the first document as a
template (.dot file) and put both macros in it. Also, save the piece of
table from the second document as an AutoText entry in the first document
(now a template). See
http://www.word.mvps.org/faqs/customization/AutoText.htm.

Use File> New to create Throw away the second document, which is no longer
necessary. Change the macros so that, instead of using InsertFile, they use
ActiveDocument.AttachedTemplate _
.AutoTextEntries("TablePiece").Insert (....)
to paste in a new chunk of table (although you should ask yourself "why not
let the user just hit Tab at the end of the row to make a new row?") Use
File> New to create a document based on the template, and away you go.

2. What do you mean by "in the last row and column is a macro"? Do you mean
there's a command button or a MacroButton field there? That can be part of
the AutoText entry. If you need to get rid of the one the user just clicked,
that can be part of the macro. Exactly how the code should look depends on
what gizmo you're using.
 
T

Tim Craig

Thank you for your quick response.

Since I'm a Super Novice trying to do operations well
beyond my level of expertise, I would have to say that I'm
the one that's confused.

1. Following is the "Insert" snipet from the macro. This
is an exit macro from a field on page two of the main
template.

Selection.InsertFile FileName:=ActiveDocument.Path
& "\Manage_Report.dot", Range:="", _
ConfirmConversions:=False, Link:=False,
Attachment:=False

So, your assumption is correct.

The first document is currently a (.dot file). This where
I originally had all four of my macros.

There are actually three separate documents that comprise
this "Word application".
The second page is attached when needed may be "attached
up to 4 times", each constituting a new and different
completed form when attached.
The third page is attached only once when needed.

Each of these files is an entire page and attached to the
first "if-and-only-if" it is needed for completing a
request.

2. Each "attached page" consists of a table that the user
can extend as needed. So, in my inexperienced mode I
created a macro and need to attach it to the last column
in the last row of the table. The reason that I created
the macro is: "I discovered that I could indeed add a new
row to the table at the end of the table simply by
pressing the "tab" key, but I do NOT get the fields that
the user must enter their data into when that is all that
I do. So this macro creates the necessary data entry
fields for the user.

-----Original Message-----
Hi Tim,

One or both of us is mightily confused. It may be just a matter of
terminology, but somehow I don't think so...

1. Exactly what are you doing to "attach" the second document to the first?
In Word and VBA, the only meaning of "attach" that sounds similar to your
task is setting a new value for the
ActiveDocument.AttachTemplate property.
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Tim.Craig > écrivait :
In this message, < Tim.Craig > wrote:

|| I have two problems that that I need help solving.
||
|| 1. I have two documents with macros. The first document
|| attaches the second document - wich I have working
|| correctly. The problem is that the macro in the second
|| document does not remain available when I attach the
|| document to the first. How do I fix this problem??
||
|| 2. The second document is basicly filled with a two
|| column table in the last row and column is a macro that
|| contatinates a new line to the end of the page for as many
|| times as the user needs. How do I add the macro to each
|| new line as it is added???
||

Please do not multipost.

If you want you can crosspost (Many newsgroups in the To: field when you
create your message.)

The reason is simple:
People may end up "wasting" their time answering a post that has already
been answered elsewhere, thus it may be very likely that their particular
response to a post be totally ignored if the reply received elsewhere was
satisfactory to the original poster.

For example, I have just "wasted" my time replying to your post in the
userforms group where I wrote more or less the same things as Jay did in
this group, except that I did not go out on a limb and suggest stuff as I
was unsure what you were trying to do....

..--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jay Freedman

Hi Tim,

Gee, I love pulling teeth... A document with form fields is distinctly
different from a document that just contains a table. Do you have this
template "protected for forms" when you use it?

Most of my previous advice still stands: store each table, or piece of
table, as an AutoText entry in the main template (which becomes the
only template). As part of that AutoText, include a MacroButton in the
last cell that invokes a macro, also in the same template.

The difference is that the macro will need to unprotect the document
first; then insert the appropriate AutoText entry; and finally
reprotect the document, using the NoReset:=True argument to avoid
clearing all the fields that have already been filled in.

As long as we're still discovering important bits of the problem:

- What version of Word are you using?
- Do all of the prospective users have the same version of Word, or
will some of them have other versions?
- What do you do with the form after it's filled in? Do you just save
and/or print the document, or do you try to extract data from the
fields into a spreadsheet or database?

The last item determines whether your macro needs to worry about the
names of the fields. Inserting the same AutoText containing fields
several times leads to fields that don't have names, which causes the
kind of problem discussed at
http://word.mvps.org/FAQs/MacrosVBA/AssignNameToFmFld.htm.
 
T

Tim Craig

With all do respect sir, YOU DID NOT WASTE YOUR TIME.
Different people have different ways of responding to a
question. While a NOVICE may not understand one persons
response, they may clearly understand anothers.

For example, you did NOT understand my initial question
and it made very little sense to you, but it was more
clearly understood by another. While his response was not
clearly understood by me (and I am still trying to better
understand his response), his response certainly made a
great deal more sense to me than yours.

As was implied in my initial request "I am a NOVICE with
this language" and my terminology may not be correct, I
had hoped that the reader would understand that and reply
with understanding to that fact. The fact that you did not
understand that all I am trying to do is add a new line
when I said concatenate (OH! yes I misspelled the word)
but reading the question through should have left little
doubt about my intention.


Bonjour,
 
C

Charles Kenyon

And what Jean-Guy was pointing out was that you can get the responses of
multiple people, in multiple newsgroups if needed, by cross-posting rather
than multiposting. Posting multiple messages on the same topic, does,
indeed, waste the volunteer time available to answer questions. He was
asking you to, in the future, post a single question. If you need input from
multiple newsgroups, put all the relevant newsgroups in the header of that
single message. If you don't know how to do this, ask. His comments were
also intended to enlighten other browsers on the expected method of posting
here.

Take a look on the MVP FAQ website under "getting help" for more reasons ase
well as other suggestions for getting answers more easily and quickly. <URL:
http://www.mvps.org/word/FindHelp/Posting.htm>



With all do respect sir, YOU DID NOT WASTE YOUR TIME.
Different people have different ways of responding to a
question. While a NOVICE may not understand one persons
response, they may clearly understand anothers.

For example, you did NOT understand my initial question
and it made very little sense to you, but it was more
clearly understood by another. While his response was not
clearly understood by me (and I am still trying to better
understand his response), his response certainly made a
great deal more sense to me than yours.

As was implied in my initial request "I am a NOVICE with
this language" and my terminology may not be correct, I
had hoped that the reader would understand that and reply
with understanding to that fact. The fact that you did not
understand that all I am trying to do is add a new line
when I said concatenate (OH! yes I misspelled the word)
but reading the question through should have left little
doubt about my intention.


Bonjour,
 
T

Tim Craig

Thank you Jay,

I apologize for making your responses more difficult, it
certainly is not my intention to do so! The information
that you are providing is invaluable to me in my attempt
to get my document/form working for our internal customers.

In response to your questions:
- What version of Word are you using?
Word 2002 (10.5815.4219)SP-2

- Do all of the prospective users have the same version of
Word, or will some of them have other versions?
YES, Sprint pushes updates to each machine nightly
to insure that we have the same version of most
applications.

- What do you do with the form after it's filled in?
The completed form is saved under a unique file
name to a document control system that is available to
users requiring access to the documents.

- Do you just save and/or print the document, or do you
try to extract data from the fields into a spreadsheet or
database?
As far as I know there is no attempt to extract
data into a spreadsheet or database.

On occasion it is necessary to retrieve the stored file,
make changes and or additions then resave the document
back to the document control system.


Tim Craig
 
T

Tim Craig

Thank you for your reply Charles!

Believe me when I say that help from these groups is
invaluable to people like myself.

While I understand that Jean-Guy was trying to provide
constructive suggestions both for myself as well as others
that may read these posts his response was interpreted as
more critical than suggestive.

Everyone, including myself must be considerate of the
audience that may read these messages.


Tim Craig
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Tim Craig > écrivait :
In this message, < Tim Craig > wrote:

| With all do respect sir, YOU DID NOT WASTE YOUR TIME.
| Different people have different ways of responding to a
| question. While a NOVICE may not understand one persons
| response, they may clearly understand anothers.
|
| For example, you did NOT understand my initial question
| and it made very little sense to you, but it was more
| clearly understood by another. While his response was not
| clearly understood by me (and I am still trying to better
| understand his response), his response certainly made a
| great deal more sense to me than yours.
|
| As was implied in my initial request "I am a NOVICE with
| this language" and my terminology may not be correct, I
| had hoped that the reader would understand that and reply
| with understanding to that fact. The fact that you did not
| understand that all I am trying to do is add a new line
| when I said concatenate (OH! yes I misspelled the word)
| but reading the question through should have left little
| doubt about my intention.
|
|

I am sorry Tim, but you did not understand my message at all. My only
message was: Please do not multipost. That is all. You chose to interpret
more than that and I am sorry for that. May be my wording was not clear
enough.
I was in no way implying that I wasted my time because you were a novice,
that your message was hard to understand or that you misspelled some words.
Notice that my initial answer to your post in the userforms group was
written in a manner as constructive as I could make it. I did not berate or
negatively criticize your post. I tried to open a dialog. It is only when I
saw Jay's reply to your identical post in the beginners group that I decided
to post my message regarding multiposting because I felt you did not know
about this slight breach of newsgroup etiquette. I post that message fairly
regularly, regardless of the poster's level of expertise or clarity. Again,
I assure you that I only posted that message so that you would know about
posting etiquette, that is all.

If I felt that it was a waste of time helping people that consider
themselves novices or who do not write clearly enough for my taste, I would
simply not participate.

By the way, read Jay's initial post again. He wrote basically the same thing
I did (he made the same assumptions and had the same questions), except
that, for example, when I suspected you meant "insert file" and not
"attach", my reaction was to ask and wait for a confirmation on your part.
Jay went ahead and assumed his guess (the same as mine) was accurate and
proceeded with a possible solution. Here you see two approaches. He guessed
and went ahead with a reply based on that guess. I guessed and ask for
confirmation in case I wasted my time and *yours* providing an answer that
was way off tracks. You were just lucky that our guesses were accurate,
otherwise after trying to understand Jay's reply you would have realized
that it was not what you needed. Believe me, I have seen this all too often.
Sometimes, it takes 7 or 8 posts for the thread to start to make sense to
the people involved because the whole thread was based on a wrong guess from
the first reply.
If I had seen Jay's reply (which I would have had you crossposted) I would
not have spent time trying understand your post and composing a message.
That is all I meant by "waste of time".

Again, sorry to have appeared to criticize your message based on its level
of expertise and clarity, not my intention at all.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jay Freedman

Hi Tim,

It looks like you're in a good position to use the AutoText-and-macros setup
I described before. There shouldn't be any complications.

For each of the two includable pages, with tables containing form fields,
select the whole page and use the Insert > AutoText > AutoText dialog to
save it as an entry in the template. Pay careful attention to the Look In
box at the bottom of the dialog -- make sure it shows your template and not
"All active templates". See
http://www.word.mvps.org/faqs/customization/AutoText.htm for some useful
background.

I'm not sure whether to recommend MacroButton fields directly in the table,
or buttons on a custom toolbar, to launch the macros. Either should work.

You'll want two macros in the template, one for each type of insert. The
general idea of the code is

Sub AddPage2Table()
Dim oRg As Range

If ActiveDocument.ProtectionType <> _
wdNoProtection Then
ActiveDocument.Unprotect
End If

Set oRg = ActiveDocument.Range
oRg.Collapse wdCollapseEnd

ActiveDocument.AttachedTemplate _
.AutoTextEntries("page2").Insert _
Where:=oRg, RichText:=True

ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, _
NoReset:=True
End Sub

This will insert the AutoText entry named "page2" at the end of the
document. You'd need a second macro that's the same except for the name of
the entry it inserts. You could add code to make sure the document doesn't
get more than four copies of one entry and one copy of the other -- but
often it's better just to trust the users to do it right.

There are probably some gotchas lurking in there, but they shouldn't be too
hard to work around.
 
G

Guest

Thank you for replying Jean-Guy, I really do appreciate
the fact that you took the time to reply to my message.

I may have been hasty in my initial assumptions, I did
have a couple of others read your reply though and their
interpretation was the same as mine.

In any case Thank You and the other people that spend so
much of their time replying to questions from those of us
that are unfamiliar with the correct terminology.

I readily understand that it can very trying and
frustrating to say the least, trying to dig down to the
requestor's real problem and understand his/her needs.

Again thank you for your response!!!!


Tim Craig
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < (e-mail address removed) > écrivait :

| Thank you for replying Jean-Guy, I really do appreciate
| the fact that you took the time to reply to my message.
|
| I may have been hasty in my initial assumptions, I did
| have a couple of others read your reply though and their
| interpretation was the same as mine.
|
| In any case Thank You and the other people that spend so
| much of their time replying to questions from those of us
| that are unfamiliar with the correct terminology.
|
| I readily understand that it can very trying and
| frustrating to say the least, trying to dig down to the
| requestor's real problem and understand his/her needs.
|
| Again thank you for your response!!!!
|

Thanks for replying as well.

I guess you did not interpret the quotation marks as I thought they would be
(I used them twice in the expressions regarding wasting time...).

I'll see if I can reword my post next time. It is a standard reply that I
use in all such cases, except, of course, for the last paragraph.

I see Jay as provided you with lots of ideas and suggestions. Try them out,
and write back if you need more help. If you get a in a different problem,
it may be useful to start a new thread.

Good luck.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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