Q: vb to reproduce a document

  • Thread starter Malcolm Dew-Jones
  • Start date
M

Malcolm Dew-Jones

Hello

I can write a macro to create a document, insert some text, apply some
formatting to it, an save everything to a file.

I would like to do that but to reproduce an existing document.

I am looking for any tools that take an existing document and determine
the vb commands that would reproduce the original document when you run
them.

If there are no existing tools that do anything like this then I may
investigate writing my own. Perhaps there's a trick in vb to make this
really easy to do already (I'm far from a vb expert). Otherwise I guess I
would have to loop over all the various collections that make up a
document and look at each object and create a vb command to create an
object of that type with the settings/text/etc of that object.

If anyone should know of existing or examples to do this sort of thing I
would appreciate hearing about them.

Thanks.
 
D

Doug Robbins - Word MVP

Dim mydoc as Document
Set mydoc = Documents.Open("path\filename of existing document")
mydoc.SaveAs "New path\filename")

Now you have created a new document the same as the exising one.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
M

Malcolm Dew-Jones

: > I am looking for any tools that take an existing document and determine
: > the vb commands that would reproduce the original document when you run
: > them.
: >


Doug Robbins - Word MVP ([email protected]) wrote:
: Dim mydoc as Document
: Set mydoc = Documents.Open("path\filename of existing document")
: mydoc.SaveAs "New path\filename")

: Now you have created a new document the same as the exising one.

I suppose it does thanks, but this wasn't what I meant. I don't want to
simply copy an existing document.

I want to have a self contained VB program that contains the sequence of
steps necessary to create a new document that happens to be the same as an
other document.

The sort of script I want would likely contain commands such as

Selection.TypeText Text:="This line will be inserted programmatically."

(amongst many other things).

In other words, I want to end up with a vb script that is similar to the
one I would have got if I had originally recorded one giant macro while
typing in the document in the first place.

Thanks.
 
D

Doug Robbins - Word MVP

There are far more efficient ways to do it. Creating a new document from a
template for example. Exactly what is the purpose?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
M

Malcolm Dew-Jones

Doug Robbins - Word MVP ([email protected]) wrote:
: There are far more efficient ways to do it. Creating a new document from a
: template for example. Exactly what is the purpose?

Well partly for interest, and partly just to expand the options
available for solving problems involving word documents.


: --
: Hope this helps.

: Please reply to the newsgroup unless you wish to avail yourself of my
: services on a paid consulting basis.

: Doug Robbins - Word MVP

: : >: > I am looking for any tools that take an existing document and determine
: > : > the vb commands that would reproduce the original document when you
: > run
: > : > them.
: > : >
: >
: >
: > Doug Robbins - Word MVP ([email protected]) wrote:
: > : Dim mydoc as Document
: > : Set mydoc = Documents.Open("path\filename of existing document")
: > : mydoc.SaveAs "New path\filename")
: >
: > : Now you have created a new document the same as the exising one.
: >
: > I suppose it does thanks, but this wasn't what I meant. I don't want to
: > simply copy an existing document.
: >
: > I want to have a self contained VB program that contains the sequence of
: > steps necessary to create a new document that happens to be the same as an
: > other document.
: >
: > The sort of script I want would likely contain commands such as
: >
: > Selection.TypeText Text:="This line will be inserted programmatically."
: >
: > (amongst many other things).
: >
: > In other words, I want to end up with a vb script that is similar to the
: > one I would have got if I had originally recorded one giant macro while
: > typing in the document in the first place.
: >
: > Thanks.



--
 

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