#1
|
|||
|
|||
Dynamically create documents
Hello,
I have to write a lot of functional designs for my company and they all use chapters that are the same every time. Sometimes i need a certain chapter the next time i dont need that chapter but several other ones. I now have all seperate chapters saved in seperated word document, like : chapter_a.docx chapter_b.docx .... I also created a visual basic code that is able to add the content of an external word document to the current document. The thing i'm looking for know is that I can show a dialog to the user from where he can select one more more chapters which are then copied in the document. [] chapter_a [x] chapter_b [] chapter_c [x] chapter_d [] chapter_e and so one. Two questions ; 1. How do I create such a dialog and pass the selected values to a subroutine 2. What is the best way to startup this code ie. when creating / opening the document the first time or can i assign a special key combination to start this dialog. ----- The code that i have now is created using the function to record a Macro but it works so far. Code:
Sub FilesToCopy() Call CopyPasteFromExternalFile("c:\isp\Hoofdstuk1.docx") Call CopyPasteFromExternalFile("c:\isp\Hoofdstuk2.docx") End Sub Sub CopyPasteFromExternalFile(strFileToPaste As String) ' ' CopyPasteFromExternalFile Macro ' Test om content van externe bestanden te kopieren ' Documents.Open FileName:=strFileToPaste, ConfirmConversions:=False, _ ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _ PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _ WritePasswordTemplate:="", Format:=wdOpenFormatAuto, XMLTransform:="" Selection.WholeStory Selection.Copy ActiveWindow.Close Selection.EndKey Unit:=wdStory Selection.PasteAndFormat (wdFormatOriginalFormatting) End Sub Hope somebody can help me out. Erik |
#2
|
||||
|
||||
What you'll need for this is a userform with checkboxes for the various chapters and code to test whether a particular checkbox is checked and, if so, import the corresponding chapter.
To see how to create & use a userform, see: http://gregmaxey.com/word_tip_pages/..._userForm.html http://www.fontstuff.com/vba/vbatut09a.htm
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Have Powerpoint dynamically update from an excel or other file? | oshkosh | PowerPoint | 3 | 04-05-2016 06:10 AM |
Linking Documents via Hyperlinks to create a "packet" | moose288 | Word | 3 | 09-22-2012 08:22 PM |
draw charts dynamically | pouya7525 | PowerPoint | 0 | 09-06-2012 10:45 AM |
Dynamically creating new drop down boxes. | dmncs | Word VBA | 1 | 05-06-2012 09:29 PM |
How do I dynamically update data in a Word Document from a database table | RSchmidt | Word | 1 | 07-14-2011 04:27 PM |