Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2006

Tip: Looking for answers? Try searching our database.

Creating a Large Document using Insert File Link

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
NYSA-HD - 24 Aug 2006 16:56 GMT
I am creating a 2000 page book from several smaller files.  I have a
directory where there is a file named for each date the file was created.  
For example, 20060102, 20060105, etc.... Where the filenames are YYYYMMDD.  
There may not be a file for every date, but all files are named by date.  I
would like to avoid master documents because of corruption issues.  My
thought was to create a document with my headers and page numbers for each
months worth of files. In each month document I need a macro that would go
out and look to the directory and insert each file in the month directory
into the new file in sequencial order as a linked file.  The field codes I am
looking to drop are { INCLUDETEXT "U:\\Project\\20060102.dot"}, etc... so
that the macro would just read the files in the folder and insert the
includetext field for each file in the folder in order.  When I look at the
final document for each month it would be all data for all dates, but I could
update the files individually and would automatically update the month
document.

Is anything like this possible?  Is there a better way to do such a document
creation?
Jezebel - 24 Aug 2006 21:44 GMT
1. It would help if you explained why you need to combine the files in the
first place. What will you do with the compound document that you can't do
with the individual files?

2. 2000 pages isn't so massive anyway, unless the files contain a lot of
graphics or complex tables. You could just build an ordinary document.

3. Why are you working with .dot files?

>I am creating a 2000 page book from several smaller files.  I have a
> directory where there is a file named for each date the file was created.
[quoted text clipped - 19 lines]
> document
> creation?
NYSA-HD - 25 Aug 2006 15:50 GMT
Basically we have a group of inputters who record data that gets written in a
journal for each date a meeting takes place.  We have automated their job by
creating .dot files for each form type for the journal entry and have text
files inserted by macros that feed the majority of the templates.  When they
open Word we have a form where they enter the date and it grabs the text and
completes the form and asks them any variable questions.  It auto saves the
file by date in a network folder.  At the end of each year we need to combine
all of these individual files into one document w/ page numbers and common
headers and footers - also a TOC and Index with a title page.  We don't see
an easy way to page number w/o combining somehow.  The document does not have
graphics...mostly straight text w/ index markers and styles.  There are
macros which run our application, but they don't need to be there when it is
combined.

What do you think is the best way to handle this?
Have I provided enough background info.

> 1. It would help if you explained why you need to combine the files in the
> first place. What will you do with the compound document that you can't do
[quoted text clipped - 28 lines]
> > document
> > creation?
Jezebel - 25 Aug 2006 22:58 GMT
1. Your inputters should be using the the .dot files as templates, so the
files you get back should be .doc files. If not, you haven't explained to
them well enough how to install the and use the templates.

2. From your description, simply combining all the docs into one big one
should be fine, particularly as it's just a yearly one-off and presumably
you don't need to do anything with the finished document except print it.

> Basically we have a group of inputters who record data that gets written
> in a
[quoted text clipped - 64 lines]
>> > document
>> > creation?
NYSA-HD - 29 Aug 2006 16:08 GMT
I'm sorry, you were right the outputted files are .doc files named for the
date YYYYMMDD.doc

What is the easiest way to combine them all in date order w/o manually
inserting each file?

> 1. Your inputters should be using the the .dot files as templates, so the
> files you get back should be .doc files. If not, you haven't explained to
[quoted text clipped - 72 lines]
> >> > document
> >> > creation?
Doug Robbins - Word MVP - 30 Aug 2006 11:12 GMT
If you put all of the documents in a folder by themselves, a macro
containing the following code should insert each of them into a new document
in the date order:

Dim MyPath As String

Dim MyName As String

Dim Source As Document, Target As Document

Dim SourceFile As Range

Dim i As Long

Dim FileList As Document

Set FileList = Documents.Add

'let user select a path

With Dialogs(wdDialogCopyFile)

   If .Display() <> -1 Then Exit Sub

   MyPath = .Directory

End With

'strip quotation marks from path

If Len(MyPath) = 0 Then Exit Sub

If Asc(MyPath) = 34 Then

   MyPath = Mid$(MyPath, 2, Len(MyPath) - 2)

End If

'get files from the selected path

'and insert them into the doc

MyName = Dir$(MyPath & "*.*")

Do While MyName <> ""

   Selection.InsertAfter MyName & vbCr

   MyName = Dir

Loop

'Sort the list of files

FileList.Range.Sort SortFieldType:=wdSortFieldAlphanumeric,
FieldNumber:="Paragraphs"

'Delete the empty paragraph that will be at the top of the list of files

FileList.Paragraphs(1).Range.Delete

'Start a new document into which each of the others will be inserted

Set Target = Documents.Add

'Iterate through the list of files, getting the name of each file, opening
it

'and inserting its contents into the Target document

For i = 1 To FileList.Paragraphs.Count

   Set SourceFile = FileList.Paragraphs(i).Range

   SourceFile.End = SourceFile.End - 1

   Set Source = Documents.Open(MyPath & SourceFile.Text)

   Target.Range.InsertAfter Source.Range.FormattedText

   Source.Close wdDoNotSaveChanges

Next i

Also see the article "Print all documents in a given folder to a single
print file" at:

http://www.word.mvps.org/FAQs/MacrosVBA/PrintAllDocsInFldr.htm

Signature

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'm sorry, you were right the outputted files are .doc files named for the
> date YYYYMMDD.doc
[quoted text clipped - 95 lines]
>> >> > document
>> >> > creation?
NYSA-HD - 30 Aug 2006 16:30 GMT
This is exactly what I wanted, but I have one issue.  The doc files I am
inserting have inherited macros.  How can the code below insert the files w/o
the macros or better yet as Links to the original documents?  When I run the
code as is all my dialogue boxes from the macros pop up, and I will no longer
need them at this point.  

I really appreciate the help with this.



> If you put all of the documents in a folder by themselves, a macro
> containing the following code should insert each of them into a new document
[quoted text clipped - 184 lines]
> >> >> > document
> >> >> > creation?
Doug Robbins - Word MVP - 30 Aug 2006 21:07 GMT
Set the macro security level to High (Tools>Macro>Security), temporarily if
necessary, then the macros in the documents will be ignored.

Signature

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

> This is exactly what I wanted, but I have one issue.  The doc files I am
> inserting have inherited macros.  How can the code below insert the files
[quoted text clipped - 220 lines]
>> >> >> > document
>> >> >> > creation?
NYSA-HD - 31 Aug 2006 17:37 GMT
This solution doesn't work b/c they are all trusted macros.  Any other ideas
to change the macro to insert files as linked objects?

> Set the macro security level to High (Tools>Macro>Security), temporarily if
> necessary, then the macros in the documents will be ignored.
[quoted text clipped - 223 lines]
> >> >> >> > document
> >> >> >> > creation?
Doug Robbins - Word MVP - 01 Sep 2006 04:52 GMT
OK, I thought it was the macro security warning to which you were referring,
but on re-reading you post see what it is.

See the article "How can I prevent Word from running macros automatically
when I create a new instance of Word, open a Word document or create a new
one?" at:

http://www.word.mvps.org/FAQs/InterDev/DisableAutoMacros.htm

Signature

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

> This solution doesn't work b/c they are all trusted macros.  Any other
> ideas
[quoted text clipped - 260 lines]
>> >> >> >> > document
>> >> >> >> > creation?
NYSA-HD - 01 Sep 2006 18:39 GMT
I tried the suggestion of Doug's and Russ, but it still ran the macros.  I
tried it before the Target command and after.  I also tried it at the
beginning under the Dim statements. I think I need to disable all macros in
the documents inserted not just the auto ones.  How would I do that?

> OK, I thought it was the macro security warning to which you were referring,
> but on re-reading you post see what it is.
[quoted text clipped - 233 lines]
> >> >> >> >> > each
> >> >> >> >> > months worth of files. In each month document I need a macro
Doug Robbins - Word MVP - 01 Sep 2006 21:10 GMT
Just what macros are being run?

Signature

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 tried the suggestion of Doug's and Russ, but it still ran the macros.  I
> tried it before the Target command and after.  I also tried it at the
[quoted text clipped - 262 lines]
>> >> >> >> >> > months worth of files. In each month document I need a
>> >> >> >> >> > macro
NYSA-HD - 05 Sep 2006 17:10 GMT
Oops my mistake.  It is an auto open macro:

Sub AutoOpen()
'StartForm.Show
   StartupMacro
End Sub

I did try placing the code you and Russ mentioned but it still tried to run.
Maybe I placed it wrong?

> Just what macros are being run?
>
[quoted text clipped - 224 lines]
> >> >> >> >> >> first place. What will you do with the compound document that
> >> >> >> >> >> you
Doug Robbins - Word MVP - 05 Sep 2006 20:27 GMT
Try putting the WordBasic.DisableAutoMacros 1 before the following line of
code:

Set Source = Documents.Open(MyPath & SourceFile.Text)

I think though that if you place the documents in a Folder location that is
not trusted and you set the Macro Security Level to high, then the macros in
those documents should be ignored without any message being displayed.

Signature

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

> Oops my mistake.  It is an auto open macro:
>
[quoted text clipped - 257 lines]
>> >> >> >> >> >> that
>> >> >> >> >> >> you
NYSA-HD - 07 Sep 2006 19:50 GMT
I modified the code as noted below adding the disable macros and also my own
line to uprotect each document before inserting.  Also a line to close the
filelist document when done.  The only thing is now I have a new issue.  Each
of my files has hidden text and special formatting.  The macro runs and
inserts the files in date order, but when the files are inserted all of the
hidden text is unhidden and all of my formatting is gone.  It says insert
formatted text in the macro but that isn't happening.  What to do next?  
Below is my modified macro I am running at this stage.  Maybe using
insertfile instead of document.open? Thanks for all the help.

Sub InsertFilesTest()

Dim MyPath As String

Dim MyName As String

Dim Source As Document, Target As Document

Dim SourceFile As Range

Dim i As Long

Dim FileList As Document

Set FileList = Documents.Add

'let user select a path

With Dialogs(wdDialogCopyFile)

   If .Display() <> -1 Then Exit Sub

   MyPath = .Directory

End With

'strip quotation marks from path

If Len(MyPath) = 0 Then Exit Sub

If Asc(MyPath) = 34 Then

   MyPath = Mid$(MyPath, 2, Len(MyPath) - 2)

End If

'get files from the selected path

'and insert them into the doc

MyName = Dir$(MyPath & "*.*")

Do While MyName <> ""

   Selection.InsertAfter MyName & vbCr

   MyName = Dir

Loop

'Sort the list of files

FileList.Range.Sort SortFieldType:=wdSortFieldAlphanumeric,
FieldNumber:="Paragraphs"

'Delete the empty paragraph that will be at the top of the list of files

FileList.Paragraphs(1).Range.Delete

'Start a new document into which each of the others will be inserted

Set Target = Documents.Add

'Iterate through the list of files, getting the name of each file,
'disabling its macros, opening each file, uprotecting it
'and and inserting its contents into the Target document

For i = 1 To FileList.Paragraphs.Count

   Set SourceFile = FileList.Paragraphs(i).Range

   SourceFile.End = SourceFile.End - 1

   WordBasic.DisableAutoMacros 1
   
   Set Source = Documents.Open(MyPath & SourceFile.Text)

   If ActiveDocument.ProtectionType <> wdNoProtection Then
      ActiveDocument.Unprotect Password:=""
   End If
   
   Target.Range.InsertAfter Source.Range.FormattedText

   Source.Close wdDoNotSaveChanges
   
Next i
FileList.Close wdDoNotSaveChanges
End Sub
-----------------------------------------------------------

> Try putting the WordBasic.DisableAutoMacros 1 before the following line of
> code:
[quoted text clipped - 212 lines]
> >> >> >> >> >> > text
> >> >> >> >> >> > files inserted by macros that feed the majority of the
Russ - 08 Sep 2006 10:42 GMT
NYSA-HD,
See a code alteration below.

> I modified the code as noted below adding the disable macros and also my own
> line to uprotect each document before inserting.  Also a line to close the
[quoted text clipped - 88 lines]
>    
>     Target.Range.InsertAfter Source.Range.FormattedText
Replace the InsertAfter line above; try:
Target.Range.Collapse Direction:=wdCollapseEnd
Target.Range.FormattedText = Source.Range.FormattedText

The example in VBA shows a similar pattern with the left side of equation
(container?) also as FormattedText. But doesn't seem to work with
InsertAfter.

>     Source.Close wdDoNotSaveChanges
>    
[quoted text clipped - 219 lines]
>>>>>>>>>>>> text
>>>>>>>>>>>> files inserted by macros that feed the majority of the

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

NYSA-HD - 11 Sep 2006 20:34 GMT
NO- This just seems to open everything up and create a new file w/ just the
last file inserted.  So far, we like the following code, but the issue we
need to resolve is having it display the entire file if the link spans more
than one page.  Any ideas?  If the file goes longer than one page it just
inserts the view of the first page.

Sub InsertFilesTest()
Dim MyPath As String
Dim MyName As String
Dim Source As Document, Target As Document
Dim SourceFile As Range
Dim i As Long
Dim FileList As Document
Set FileList = Documents.Add
'let user select a path
With Dialogs(wdDialogCopyFile)
  If .Display() <> -1 Then Exit Sub
      MyPath = .Directory
End With
'strip quotation marks from path
If Len(MyPath) = 0 Then Exit Sub
If Asc(MyPath) = 34 Then
  MyPath = Mid$(MyPath, 2, Len(MyPath) - 2)
End If
'get files from the selected path
'and insert them into the doc
MyName = Dir$(MyPath & "*.*")
Do While MyName <> ""
  Selection.InsertAfter MyName & vbCr
  MyName = Dir
Loop
'Sort the list of files
FileList.Range.Sort SortFieldType:=wdSortFieldAlphanumeric,
FieldNumber:="Paragraphs"
'Delete the empty paragraph that will be at the top of the list of files
FileList.Paragraphs(1).Range.Delete
'Start a new document into which each of the others will be inserted
Set Target = Documents.Add
'Iterate through the list of files, getting the name of each file,
'disabling its macros, opening each file, uprotecting it
'and and inserting its contents into the Target document as a link
For i = 1 To FileList.Paragraphs.Count
  Set SourceFile = FileList.Paragraphs(i).Range
  SourceFile.End = SourceFile.End - 1
  WordBasic.DisableAutoMacros 1
  Selection.EndKey unit:=wdStory
  Selection.InlineShapes.AddOLEObject ClassType:="Word.Document.8",
FileName:=MyPath & SourceFile.Text, LinkToFile:=True
  Next i
'Close FileList Document
FileList.Close wdDoNotSaveChanges
End Sub

> NYSA-HD,
> See a code alteration below.
[quoted text clipped - 237 lines]
> >>>>>>>>>> FileList.Range.Sort SortFieldType:=wdSortFieldAlphanumeric,
> >>>>>>>>>> FieldNumber:="Paragraphs"
Russ - 01 Oct 2006 00:15 GMT
NYSA-HD,

> NO- This just seems to open everything up and create a new file w/ just the
> last file inserted.
...You said "The macro runs and inserts the files in date order, but when
the files are inserted all of the hidden text is unhidden and all of my
formatting is gone.  It says insert formatted text in the macro but that
isn't happening.  What to do next? Below is my modified macro I am running
at this stage."
...And I suggested replacing one line with two to get the formatting.
My first line should have done what '.InsertAfter' implies by collapsing to
the end of the target file and the second line should have brought in new
*formatted* text at the end of the file during each iteration of the loop.
Maybe you didn't use my collapse line in the macro that you were 'running at
that stage.'

> So far, we like the following code, but the issue we
> need to resolve is having it display the entire file if the link spans more
[quoted text clipped - 291 lines]
>>>>>>>>>>>> FileList.Range.Sort SortFieldType:=wdSortFieldAlphanumeric,
>>>>>>>>>>>> FieldNumber:="Paragraphs"

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Russ - 01 Sep 2006 04:59 GMT
NYSA-HD,

Using...
WordBasic.DisableAutoMacros 0
WordBasic.DisableAutoMacros 1
You might be able disable and enable auto macros respectively and still use
Doug's macro without dialogs popping up as each file is opened.
See link below for source of this information.

http://tinyurl.com/fe5ds

> This solution doesn't work b/c they are all trusted macros.  Any other ideas
> to change the macro to insert files as linked objects?
[quoted text clipped - 226 lines]
>>>>>>>>> document
>>>>>>>>> creation?

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Russ - 08 Sep 2006 08:25 GMT
FYI,
> NYSA-HD,
>  
> Using...
> WordBasic.DisableAutoMacros 0
> WordBasic.DisableAutoMacros 1

The message link I referenced has confusing sentence structure. So to be
clear:
WordBasic.DisableAutoMacros 1 ==== Disables Auto Macros
WordBasic.DisableAutoMacros 0 ==== Enables Auto Macros

> You might be able disable and enable auto macros respectively and still use
> Doug's macro without dialogs popping up as each file is opened.
[quoted text clipped - 232 lines]
>>>>>>>>>> document
>>>>>>>>>> creation?

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID


Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.