Using organizercopy to copy styles

D

Dan

I am using a macro to copy styles from one document (gendoc) to another (newdoc). Basically, I have a program that generates a document, and then I am using macros to pull in data from that generated document. I need to copy the styles over in order to pull in the tab stops that the generated document has created.

Now, sometimes this works just fine, other times it causes Word to crash. I thought it was because the file I was copying to was not yet saved in a real location, and thus the .fullname reference I'm using with the organizercopy command didn't really mean anything yet, but using a saved document has still caused Word to crash seemingly randomly. Any idea if there is something simple I could be missing? I should note that the styles that I'm copying do already exist in the document I'm copying them to (newdoc), I'm just trying to overwrite them. I would delete those styles first, before overwriting them, but wouldn't that lose any references to those styles in the document (newdoc) I'm trying to copy these styles to?

Any help would be appreciated.
 
J

Jezebel

Why not create a template that has the style definitions you want, then use
your that for your generated document? Or attach that template to your
document and update styles?



Dan said:
I am using a macro to copy styles from one document (gendoc) to another
(newdoc). Basically, I have a program that generates a document, and then I
am using macros to pull in data from that generated document. I need to
copy the styles over in order to pull in the tab stops that the generated
document has created.
Now, sometimes this works just fine, other times it causes Word to crash.
I thought it was because the file I was copying to was not yet saved in a
real location, and thus the .fullname reference I'm using with the
organizercopy command didn't really mean anything yet, but using a saved
document has still caused Word to crash seemingly randomly. Any idea if
there is something simple I could be missing? I should note that the styles
that I'm copying do already exist in the document I'm copying them to
(newdoc), I'm just trying to overwrite them. I would delete those styles
first, before overwriting them, but wouldn't that lose any references to
those styles in the document (newdoc) I'm trying to copy these styles to?
 
D

Dan

The style definitions are different every time, depending on the user's needs and specifications. How many things they need to fit on a page, etc...
 
C

Charles Kenyon

Don't know why it is crashing, but I suspect that there can't be that many
variations; if there were, you wouldn't be able to program it. If you are
actually creating or modifying the styles on the fly and then copying them,
why not do the creation/modification in the result document instead?

If necessary to keep users from accessing without your program, store your
templates somewhere outside of the normal templates folder.

Another tip is when using OrganizerCopy to copy sets of styles copy them
three times. This preserves links among styles. That is, copy all styles
once, then again, and yet a third time.

Otherwise, post your actual code here (not as an attachment but in the body
of your message) and someone may help you debug it.
--

Charles Kenyon

See the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

Dan said:
The style definitions are different every time, depending on the user's
needs and specifications. How many things they need to fit on a page,
etc...
 
W

Word Heretic

G'day Dan <[email protected]>,

Mostly I find it fails so I gen the styles via macro.

Steve Hudson
Word Heretic Sydney Australia
Tricky stuff with Word or words

Email: WordHeretic at tpg.com.au


Dan was spinning this yarn:
 
D

Dan

The main thing I'm trying to copy over into my new document is the tab stops contained in two styles. Any tips on how to determine the tab stop settings for each style, perhaps save those settings to variables, and then create new styles using those tab settings?
 
D

Dan

Here is the code I'm using

newdoc= ActiveDocument.Nam
Set olddoc= Documents.Open(fullfilep, ReadOnly = True
' fullfilep = a filepath that the user has entered, in this case I've been entering C:\My Documents\B01 - DOC.doc, as this is the test file I'm trying to pull in data from

Application.OrganizerCopy Source:=Documents(olddoc).FullName,
Destination:=Documents(newdoc).FullName,
Name:="Normal", Object:=wdOrganizerObjectStyle
Application.OrganizerCopy Source:=Documents(olddoc).FullName,
Destination:=Documents(newdoc).FullName,
Name:="qtxNum", Object:=wdOrganizerObjectStyle
Application.OrganizerCopy Source:=Documents(olddoc).FullName,
Destination:=Documents(newdoc).FullName,
Name:="qtxPct", Object:=wdOrganizerObjectStyle

I'm wondering if the Normal style could be causing the crash, or if when it's seemingly working and not crashing, it's just because the style copying has failed that time around (since a lot of people seem to say the whole copy process is iffy).
 
W

Word Heretic

G'day Dan said:
(since a lot of people seem to say the whole copy process is iffy).

IMHO, you've hit the nail on the head.

Steve Hudson
Word Heretic Sydney Australia
Tricky stuff with Word or words

Email: WordHeretic at tpg.com.au


Dan was spinning this yarn:
 
D

Dan

Well, I figured it out. It was the attempt to copy the Normal style. All other styles copy just fine, without any crashing. Just that style causes problems.

----- Dan wrote: -----

Here is the code I'm using:

newdoc= ActiveDocument.Name
Set olddoc= Documents.Open(fullfilep, ReadOnly = True)
' fullfilep = a filepath that the user has entered, in this case I've been entering C:\My Documents\B01 - DOC.doc, as this is the test file I'm trying to pull in data from.

Application.OrganizerCopy Source:=Documents(olddoc).FullName, _
Destination:=Documents(newdoc).FullName, _
Name:="Normal", Object:=wdOrganizerObjectStyles
Application.OrganizerCopy Source:=Documents(olddoc).FullName, _
Destination:=Documents(newdoc).FullName, _
Name:="qtxNum", Object:=wdOrganizerObjectStyles
Application.OrganizerCopy Source:=Documents(olddoc).FullName, _
Destination:=Documents(newdoc).FullName, _
Name:="qtxPct", Object:=wdOrganizerObjectStyles

I'm wondering if the Normal style could be causing the crash, or if when it's seemingly working and not crashing, it's just because the style copying has failed that time around (since a lot of people seem to say the whole copy process is iffy).
 
C

Charles Kenyon

That must be why I never have problems, I don't use normal style or styles
based on it, and so don't copy it.
--

Charles Kenyon

See the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

Dan said:
Well, I figured it out. It was the attempt to copy the Normal style. All
other styles copy just fine, without any crashing. Just that style causes
problems.
----- Dan wrote: -----

Here is the code I'm using:

newdoc= ActiveDocument.Name
Set olddoc= Documents.Open(fullfilep, ReadOnly = True)
' fullfilep = a filepath that the user has entered, in this case I've
been entering C:\My Documents\B01 - DOC.doc, as this is the test file I'm
trying to pull in data from.
Application.OrganizerCopy Source:=Documents(olddoc).FullName, _
Destination:=Documents(newdoc).FullName, _
Name:="Normal", Object:=wdOrganizerObjectStyles
Application.OrganizerCopy Source:=Documents(olddoc).FullName, _
Destination:=Documents(newdoc).FullName, _
Name:="qtxNum", Object:=wdOrganizerObjectStyles
Application.OrganizerCopy Source:=Documents(olddoc).FullName, _
Destination:=Documents(newdoc).FullName, _
Name:="qtxPct", Object:=wdOrganizerObjectStyles

I'm wondering if the Normal style could be causing the crash, or if
when it's seemingly working and not crashing, it's just because the style
copying has failed that time around (since a lot of people seem to say the
whole copy process is iffy).
 

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