I have a tempate with some vba code that fills in teh document from a
database.
The code works by writing to ActiveDocument

I want to modify this so that it can read in a text file of values and
create one document for each row.

Within the code How do I add a new document and then make it the active
document sio it is written to?. I have tried using this but it just
writes to the same document each time.

Thanks

Application.Documents.Add (ActiveDocument.Path & "/" &
ActiveDocument.Name)
Application.Documents(Application.Documents.Count).Activate

RE: Opening a new document from a template by Cooz

Cooz
Fri Jun 02 09:05:01 CDT 2006

Hi hals_left,

Leave out 'Application.Documents(Application.Documents.Count).Activate'
The doc you want is the active document after ' Application.Documents.Add
(ActiveDocument.Path & "/" & ActiveDocument.Name)'

Good luck,
Cooz




"hals_left" wrote:

>
> I have a tempate with some vba code that fills in teh document from a
> database.
> The code works by writing to ActiveDocument
>
> I want to modify this so that it can read in a text file of values and
> create one document for each row.
>
> Within the code How do I add a new document and then make it the active
> document sio it is written to?. I have tried using this but it just
> writes to the same document each time.
>
> Thanks
>
> Application.Documents.Add (ActiveDocument.Path & "/" &
> ActiveDocument.Name)
> Application.Documents(Application.Documents.Count).Activate
>
>

Re: Opening a new document from a template by hals_left

hals_left
Fri Jun 02 09:30:38 CDT 2006

It doesnt work - It just writes several times to one document, it doent
even add new documents when I step through the line:
Application.Documents.Add (ActiveDocument.Path & "/" &
ActiveDocument.Name)

Cooz wrote:
> Hi hals_left,
>
> Leave out 'Application.Documents(Application.Documents.Count).Activate'
> The doc you want is the active document after ' Application.Documents.Add
> (ActiveDocument.Path & "/" & ActiveDocument.Name)'
>
> Good luck,
> Cooz
>
>
>
>
> "hals_left" wrote:
>
> >
> > I have a tempate with some vba code that fills in teh document from a
> > database.
> > The code works by writing to ActiveDocument
> >
> > I want to modify this so that it can read in a text file of values and
> > create one document for each row.
> >
> > Within the code How do I add a new document and then make it the active
> > document sio it is written to?. I have tried using this but it just
> > writes to the same document each time.
> >
> > Thanks
> >
> > Application.Documents.Add (ActiveDocument.Path & "/" &
> > ActiveDocument.Name)
> > Application.Documents(Application.Documents.Count).Activate
> >
> >


Re: Opening a new document from a template by hals_left

hals_left
Fri Jun 02 09:37:44 CDT 2006

I tried running this line twice in the vba editor and the first time it
adds a document to a new template project the second time it fails
because the Path and anme are empty, any ideas ?


Application.Documents.Add (ActiveDocument.Path & "/" &
ActiveDocument.Name)
hals_left wrote:
> It doesnt work - It just writes several times to one document, it doent
> even add new documents when I step through the line:
> Application.Documents.Add (ActiveDocument.Path & "/" &
> ActiveDocument.Name)
>
> Cooz wrote:
> > Hi hals_left,
> >
> > Leave out 'Application.Documents(Application.Documents.Count).Activate'
> > The doc you want is the active document after ' Application.Documents.Add
> > (ActiveDocument.Path & "/" & ActiveDocument.Name)'
> >
> > Good luck,
> > Cooz
> >
> >
> >
> >
> > "hals_left" wrote:
> >
> > >
> > > I have a tempate with some vba code that fills in teh document from a
> > > database.
> > > The code works by writing to ActiveDocument
> > >
> > > I want to modify this so that it can read in a text file of values and
> > > create one document for each row.
> > >
> > > Within the code How do I add a new document and then make it the active
> > > document sio it is written to?. I have tried using this but it just
> > > writes to the same document each time.
> > >
> > > Thanks
> > >
> > > Application.Documents.Add (ActiveDocument.Path & "/" &
> > > ActiveDocument.Name)
> > > Application.Documents(Application.Documents.Count).Activate
> > >
> > >


Re: Opening a new document from a template by Cooz

Cooz
Fri Jun 02 10:01:02 CDT 2006

Hi hals_left,

This macro makes 10 new documents based on the current document, which, I
suppose, is more or less is what you want. You will have to modify it a
little to suit your needs.

Sub NumDocs()
Dim strSourceDoc As String, intI As Integer

strSourceDoc = ActiveDocument.FullName
For intI = 1 To 10
Documents.Add strSourceDoc
Next intI

End Sub

Make sure to have the correct document (one that is already saved to disk)
active when you run the macro.

Good luck,
Cooz


"hals_left" wrote:

> I tried running this line twice in the vba editor and the first time it
> adds a document to a new template project the second time it fails
> because the Path and anme are empty, any ideas ?
>
>
> Application.Documents.Add (ActiveDocument.Path & "/" &
> ActiveDocument.Name)
> hals_left wrote:
> > It doesnt work - It just writes several times to one document, it doent
> > even add new documents when I step through the line:
> > Application.Documents.Add (ActiveDocument.Path & "/" &
> > ActiveDocument.Name)
> >
> > Cooz wrote:
> > > Hi hals_left,
> > >
> > > Leave out 'Application.Documents(Application.Documents.Count).Activate'
> > > The doc you want is the active document after ' Application.Documents.Add
> > > (ActiveDocument.Path & "/" & ActiveDocument.Name)'
> > >
> > > Good luck,
> > > Cooz
> > >
> > >
> > >
> > >
> > > "hals_left" wrote:
> > >
> > > >
> > > > I have a tempate with some vba code that fills in teh document from a
> > > > database.
> > > > The code works by writing to ActiveDocument
> > > >
> > > > I want to modify this so that it can read in a text file of values and
> > > > create one document for each row.
> > > >
> > > > Within the code How do I add a new document and then make it the active
> > > > document sio it is written to?. I have tried using this but it just
> > > > writes to the same document each time.
> > > >
> > > > Thanks
> > > >
> > > > Application.Documents.Add (ActiveDocument.Path & "/" &
> > > > ActiveDocument.Name)
> > > > Application.Documents(Application.Documents.Count).Activate
> > > >
> > > >
>
>