PDA

View Full Version : Merging word documents



NicolasV
01-07-2010, 02:42 PM
Hi everyone, im not a VBA programmer, im c# programmer, but in my job context I was oblige to use VBA. So... my project is to simplify template, each Word template got multiple section. I decide to create a userform whit each possible section of the template. My section are represent by checkbox each section is in a single word document. now i want to merge each section that is tchecked in a new word document, I all ready program all the thing I just need to know how pick up a word document whit the path and everything and put it in my new document that I've created. Some one can help me plz?

And sory if my english is not very good my primary language is french.

fumei
01-07-2010, 03:29 PM
1. Are these "sectons" real Word-defined Sections - i.e. they are separated by SectionBreaks? If they are, this is fairly easy. Demo attached. Click "Show The Form" on the top toolbar.

The document has four Sections, each with its own text - "This is text from SECTION X."

When you click "Show The Form" you get a userform. Check whatever Sections you wish, and then click OK. The OK button creates a new document, and copies the selected Sections into that new document.

2. "I just need to know how pick up a word document whit the path and everything and put it in my new document that I've created. "

Could you explain this a bit more? It sounds like you want to open a specific and existing document and put the whole document in some new dcoument.

This is different from trying to get Sections out.

NicolasV
01-08-2010, 07:34 AM
"Could you explain this a bit more? It sounds like you want to open a specific and existing document and put the whole document in some new dcoument."

Actualy yes, that's what im trying to do, here a part of my code

Private Sub OptimisationNext_Click()
Documents.Add DocumentType:=wdNewBlankDocument



'INSÉRER PAGE DE PRÉSENTATION ' INSERT PRESENTATION PAGE

'INSÉRER PAGE BLANCHE POUR TABLE DES MATIÈRES ' INSERT BLANK PAGE


If propo.Value = True Then
'CODE POUR IMPORTER LE DOC WORD PROPOSITION POUR MESURE DE PERFORMANCE AVEC GOOGLE ANALYTICS 'CODE TO INSERT THE SPECIFIC WORD DOCUMENT FOR PROPOSITION --- PATH FOR THE SPECIFIED WORD DOCUMENT : Y:\backup\backup_nick\TemplateAutomatiser\optimisation\Proposition_Strategi e_Internet.docx
End If

If recapitulatif.Value = True Then
'CODE POUR IMPORTER LE DOC WORD RÉCAPITULATIF DU PROJET 'INSERT SPECIFIC PAGE FOR "RECAPITULATIF" PATH FOR THE SPECIFIED WORD DOCUMENT : Y:\backup\backup_nick\TemplateAutomatiser\optimisation\Recapitulatif_demand e.docx
End If

If Apropos.Value = True Then
'CODE POUR IMPORTER LE DOC WORD À PROPOS D'ADVISO PATH FOR THE SPECIFIED WORD DOCUMENT :Y:\backup\backup_nick\TemplateAutomatiser\optimisation\A_Propos_Adviso.doc x
End If

If ReferencementOrganique.Value = True Then
'CODE POUR IMPORTER LE DOC WORD rÉFÉRENCEMENT ORGANIQUE EXPLIQUÉ PATH FOR THE SPECIFIED WORD DOCUMENT :Y:\backup\backup_nick\TemplateAutomatiser\optimisation\Referencement_Organ ique_Explique.docx
End If

If ReferencementPersonnalisee.Value = True Then
'CODE POUR IMPORTER LE DOC WORD rÉFÉRENCEMENT APPROCHE PERSONNALISÉE PATH FOR THE SPECIFIED WORD DOCUMENT :Y:\backup\backup_nick\TemplateAutomatiser\optimisation\Referencement_Appro che_Personnalisee.docx
End If

If CommuniqueDePresse.Value = True Then
'CODE POUR IMPORTER LE DOC WORD COMMUNIQUÉ DE PRESSE SOCIAL PATH FOR THE SPECIFIED WORD DOCUMENT :Y:\backup\backup_nick\TemplateAutomatiser\optimisation\Communique_Presse_S ocial.docx
End If

If Ergonomie.Value = True Then
'CODE POUR IMPORTER LE DOC WORD ERGONOMIE PATH FOR THE SPECIFIED WORD DOCUMENT :Y:\backup\backup_nick\TemplateAutomatiser\optimisation\Ergonomie.docx
End If

If ImplantationGoogleAnalytics.Value = True Then
'CODE POUR IMPORTER LE DOC WORD IMPLANTATION GOOGLE ANALYTICS PATH FOR THE SPECIFIED WORD DOCUMENT :Y:\backup\backup_nick\TemplateAutomatiser\optimisation\Implantation_Google _Analytics.docx
End If

If OptionSupplementaire.Value = True Then
'CODE POUR IMPORTER LE DOC WORD OPTIONS PATH FOR THE SPECIFIED WORD DOCUMENT :Y:\backup\backup_nick\TemplateAutomatiser\optimisation\Options.docx
End If

If cout.Value = True Then
'CODE POUR IMPORTER LE DOC WORD COUT ET ÉCHÉANCIER PATH FOR THE SPECIFIED WORD DOCUMENT :Y:\backup\backup_nick\TemplateAutomatiser\optimisation\Echeancier_Et_Cout. docx
End If

If clause.Value = True Then
'CODE POUR IMPORTER LE DOC WORD CLAUSES COMPLÉMENTAIRES PATH FOR THE SPECIFIED WORD DOCUMENT :Y:\backup\backup_nick\TemplateAutomatiser\optimisation\Clauses_Complementa ires.docx
End If

If approbation.Value = True Then
'CODE POUR IMPORTER LE DOC WORD APPROBATION PATH FOR THE SPECIFIED WORD DOCUMENT :Y:\backup\backup_nick\TemplateAutomatiser\optimisation\Approbation.docx
End If

If Realisation.Value = True Then
'CODE POUR IMPORTER LE DOC WORD RÉALISATIONS EN RÉFÉRENCEMENT PATH FOR THE SPECIFIED WORD DOCUMENT :Y:\backup\backup_nick\TemplateAutomatiser\optimisation\Realisation_Referen cement.docx
End If

If Annexes.Value = True Then
'CODE POUR IMPORTER LE DOC WORD ANNEXES PATH FOR THE SPECIFIED WORD DOCUMENT :Y:\backup\backup_nick\TemplateAutomatiser\optimisation\Annexes.docx
End If

propo.Value = False
recapitulatif.Value = False
Apropos.Value = False
ReferencementOrganique.Value = False
ReferencementPersonnalisee.Value = False
CommuniqueDePresse.Value = False
Ergonomie.Value = False
ImplantationGoogleAnalytics.Value = False
OptionSupplementaire.Value = False
cout.Value = False
clause.Value = False
approbation.Value = False
Realisation.Value = False
Annexes.Value = False


Me.Hide


ActiveDocument.Save
End Sub



So you can see that i create a new word document, and now i just want to Import/add/copy/etc, an specified document in a specified path.

How can i do that?

Thx

Nick

fumei
01-12-2010, 11:43 AM
' this makes a new document
Documents.Add

' this inserts a specific file into that new document

ActiveDocument.Range InsertFile "Y:\backup\backup_nick\TemplateAutomatiser\optimisation\Annexes.docx"

But if you are inserting the whole file, why are you creating a new blank file?

NicolasV
01-12-2010, 12:06 PM
Because I insert many document in this new document but I've found the anwser.

I got a new question for you guys, i made a VBA word Macro on my personal computer, and i put the frame into TemplateProject(normal), but if I want to export my project to everyone, is there a way to make a .exe of my Macro or something like that, thx

fumei
01-12-2010, 12:26 PM
An .EXE? You can make .EXE files using VB (not VBA). Not sure if that would solve things.

You can make code accessible to other by:

1. having the code in a module in the document

2. having the code in the document template file that is accessible to the user.

3. having the code in a global template (an Add-in)