Opening a new document from a template

H

hals_left

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
 
C

Cooz

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
 
H

hals_left

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)
 
H

hals_left

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)
 
C

Cooz

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
 

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