Enregistrer un .doc avec un nom issu d'un formulaire

fspada Messages postés 3 Date d'inscription vendredi 2 mai 2008 Statut Membre Dernière intervention 5 mai 2008 - 2 mai 2008 à 12:26
cs_loulou69 Messages postés 672 Date d'inscription mercredi 22 janvier 2003 Statut Membre Dernière intervention 2 juin 2016 - 5 mai 2008 à 15:21
Bonjour à tous,

C'est bien la première fois que j'utilise un forum pour trouver un coup de main.
J'ai cherché pendant des heures sur le net et sur des tchats des connaisseurs de VB pour trouver de l'aide mais impossible de trouver une réponse. Je suis d'ailleur étonné que personne n'ai déjà posé cette question car ça devrait servir à beaucoup. 3 raisons possibles : soit finalement personne n'en a besoin, soit je n'ai pas trouvé, soit c'est si simple que personne ne pose la question.

Voilà le sujet :
J'ai créer un modèle sous Word me permettant de remplir un document type formulaire. Dans ce document j'ai plusieurs champs dont "NOM", "Prénom", "Datedujour".
A partir de ça j'aimerai faire une macro me permettant d'enregistrer le nouveau document avec un nom du type : NOM Prénom Datedujour.doc (exemple : DUPONT Jean 02.05.08.doc). 

Merci du coup de main.

5 réponses

cs_loulou69 Messages postés 672 Date d'inscription mercredi 22 janvier 2003 Statut Membre Dernière intervention 2 juin 2016 1
2 mai 2008 à 15:57
Oui, c'est si simple...
ActiveDocument.SaveAs "DUPONT Jean 02.05.08.doc"
0
fspada Messages postés 3 Date d'inscription vendredi 2 mai 2008 Statut Membre Dernière intervention 5 mai 2008
3 mai 2008 à 22:18
Non non c'était un simple exemple. Je cherche à donner un nom de document en fonction de champs variables. Je voudrais en fait automatiser la détermination du nom de document.
0
cs_loulou69 Messages postés 672 Date d'inscription mercredi 22 janvier 2003 Statut Membre Dernière intervention 2 juin 2016 1
5 mai 2008 à 09:49
Après un petit week-end, me revoilà

Quels sont tes champs (signets, ...) ? Sais tu les lire en VBA.


Sur MVPS , interception de l'evenement Save : http://word.mvps.org/FAQs/MacrosVBA/InterceptSavePrint.htm


Sinon autre solution d'automatisation


En créant un module AutoNew


et en enregistrant une procédure FichierEnregistrer ou FichierEnregistrerSous sur une version française d'Office


Public Sub FichierEnregistrer()
MesChamps=LireLesChamps


ActiveDocument.Save  MesChamps & ".doc"


End Sub


 


 


 


 
0
fspada Messages postés 3 Date d'inscription vendredi 2 mai 2008 Statut Membre Dernière intervention 5 mai 2008
5 mai 2008 à 14:42
Tout d'abord merci pour ton intérêt pour ce sujet. 
J'ai ouvert mon document avec Microsoft Script Editor et voilà ce que ça donne : 

------------------------------------------------------------------------------------------------------------------------------------

<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">


<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 11">
<meta name=Originator content="Microsoft Word 11">
<link rel=File-List href="document_fichiers/filelist.xml">
<link rel=Edit-Time-Data href="document_fichiers/editdata.mso">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<title>mauvais</title>
<!--[if gte mso 9]><xml>
 <o:DocumentProperties>
  <o:Author>Fabien_et_Marion</o:Author>
  <o:Template>bilans orthoptiques</o:Template>
  <o:LastAuthor>Fabien_et_Marion</o:LastAuthor>
  <o:Revision>2</o:Revision>
  <o:TotalTime>2</o:TotalTime>
  <o:Created>2008-05-05T12:32:00Z</o:Created>
  <o:LastSaved>2008-05-05T12:34:00Z</o:LastSaved>
  1

  <o:Words>19</o:Words>
  <o:Characters>106</o:Characters>
  <o:Lines>1</o:Lines>
  1

  <o:CharactersWithSpaces>124</o:CharactersWithSpaces>
  <o:Version>11.9999</o:Version>
 </o:DocumentProperties>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:View>Print</w:View>
  <w:Zoom>75</w:Zoom>
  <w:AttachedTemplate
   HRef="C:\bilans orthoptiques.dot"></w:AttachedTemplate>
  <w:DocumentProtectionNotEnforced>Forms</w:DocumentProtectionNotEnforced>
  <w:HyphenationZone>21</w:HyphenationZone>
  <w:PunctuationKerning/>
  <w:ValidateAgainstSchemas/>
  <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
  <w:IgnoreMixedContent>false</w:IgnoreMixedContent>
  <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
  <w:Compatibility>
   <w:BreakWrappedTables/>
   <w:SnapToGridInCell/>
   <w:WrapTextWithPunct/>
   <w:UseAsianBreakRules/>
   <w:DontGrowAutofit/>
  </w:Compatibility>
  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
 </w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:LatentStyles DefLockedState="false" LatentStyleCount="156">
 </w:LatentStyles>
</xml><![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
 {font-family:Wingdings;
 panose-1:5 0 0 0 0 0 0 0 0 0;
 mso-font-charset:2;
 mso-generic-font-family:auto;
 mso-font-pitch:variable;
 mso-font-signature:0 268435456 0 0 -2147483648 0;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
 {mso-style-parent:"";
 margin:0cm;
 margin-bottom:.0001pt;
 mso-pagination:widow-orphan;
 font-size:12.0pt;
 font-family:"Times New Roman";
 mso-fareast-font-family:"Times New Roman";}
@page Section1
 {size:595.3pt 841.9pt;
 margin:70.85pt 70.85pt 70.85pt 70.85pt;
 mso-header-margin:35.4pt;
 mso-footer-margin:35.4pt;
 mso-paper-source:0;}
div.Section1
 {page:Section1;}
 /* List Definitions */
 @list l0
 {mso-list-id:1375076796;
 mso-list-type:hybrid;
 mso-list-template-ids:724874986 268356258 67895299 67895301 67895297 67895299 67895301 67895297 67895299 67895301;}
@list l0:level1
 {mso-level-start-at:2;
 mso-level-number-format:bullet;
 mso-level-text:-;
 mso-level-tab-stop:153.0pt;
 mso-level-number-position:left;
 margin-left:153.0pt;
 text-indent:-18.0pt;
 font-family:"Times New Roman";
 mso-fareast-font-family:"Times New Roman";}
ol
 {margin-bottom:0cm;}
ul
 {margin-bottom:0cm;}
-->
</style>
<!--[if gte mso 10]>
<style>
 /* Style Definitions */
 table.MsoNormalTable
 {mso-style-name:"Tableau Normal";
 mso-tstyle-rowband-size:0;
 mso-tstyle-colband-size:0;
 mso-style-noshow:yes;
 mso-style-parent:"";
 mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
 mso-para-margin:0cm;
 mso-para-margin-bottom:.0001pt;
 mso-pagination:widow-orphan;
 font-size:10.0pt;
 font-family:"Times New Roman";
 mso-ansi-language:#0400;
 mso-fareast-language:#0400;
 mso-bidi-language:#0400;}
</style>
<![endif]--><!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="2050"/>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1"/>
 </o:shapelayout></xml><![endif]-->
</head>






<!--[if supportFields]> FORMTEXT <![endif]-->NOM<!--[if gte mso 9]><xml>
 <w:data>FFFFFFFF0000000000000600540065007800740065003100000003004E004F004D0000000A004D0041004A0055005300430055004C0045005300000000000000000000000000000000000000</w:data>
</xml><![endif]--><!--[if supportFields]><![endif]--> <!--[if supportFields]> FORMTEXT <![endif]-->Prénom<!--[if gte mso 9]><xml>
 <w:data>FFFFFFFF00000000000006005400650078007400650032000000060050007200E9006E006F006D00000012005000720065006D006900E8007200650020006D0061006A0075007300630075006C006500000000000000000000000000000000000000</w:data>
</xml><![endif]--><!--[if supportFields]><![endif]-->


né(e) le <!--[if supportFields]> FORMTEXT <![endif]-->01/01/01<!--[if gte mso 9]><xml>
 <w:data>FFFFFFFF001000000000060054006500780074006500330000000800300031002F00300031002F003000310000000800640064002F004D004D002F0079007900000000000000000000000000000000000000</w:data>
</xml><![endif]--><!--[if supportFields]><![endif]-->


<!--[if gte vml 1]><v:shapetype id="_x0000_t201"
 coordsize="21600,21600" o:spt="201" path="m,l,21600r21600,l21600,xe">
 <v:stroke joinstyle="miter"/>
 <v:path shadowok="f" o:extrusionok="f" strokeok="f" fillok="f" o:connecttype="rect"/>
 <o:lock v:ext="edit" shapetype="t"/>
</v:shapetype><v:shape id="_x0000_s1026" type="#_x0000_t201" style='position:absolute;
 margin-left:243pt;margin-top:7.8pt;width:205.8pt;height:27pt;z-index:1'
 filled="f" stroked="f">
 <![if gte mso 9]><v:imagedata src="document_fichiers/image001.wmz" o:title=""/>
 <![endif]><o:lock v:ext="edit" aspectratio="t"/>
</v:shape><![endif]--><![if !vml]>


 ----

  ,
 
 ----

  ,
  <![endif]><object classid="CLSID:D7053240-CE69-11CD-A777-00DD01143C57"
   id=CommandButton1 v:shapes="_x0000_s1026" class=shape width=274 height=36>
  
  
  
  
  
  
  
  
  
  </object><![if !vml]>,
 


<![endif]>&nbsp;


&nbsp;


&nbsp;




Bilan du&nbsp;: <!--[if supportFields]> FORMTEXT <![endif]-->lundi 1er janvier
2001<!--[if gte mso 9]><xml>
 <w:data>FFFFFFFF0010000000000600540065007800740065003400000016006C0075006E0064006900200031006500720020006A0061006E007600690065007200200032003000300031000000100064006400640064002000640020004D004D004D004D0020007900790079007900000000000000000000000000000000000000</w:data>
</xml><![endif]--><!--[if supportFields]><![endif]-->


&nbsp;


&nbsp;






</html>
------------------------------------------------------------------------------------------------------------------------------------
Je ne touche absolument pas (à mon grand regret) sur Visual Basic ni sur n'importe quel language de programmation.
J'ai essayé avec les infos que tu m'as fourni mais je n'ai pas réussi à m'en sortir.

merci pour le temps que tu y passes
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cs_loulou69 Messages postés 672 Date d'inscription mercredi 22 janvier 2003 Statut Membre Dernière intervention 2 juin 2016 1
5 mai 2008 à 15:21
j'ai bien testé ma macro "Module" AutoOpen / Sub EnregistrerSous avant de publier ma dernière réponse : cela fonctionne
J'ai même trouvé que si on envoi la commande Sendkeys suivi du nom du fichier construit et bien cela implicite un nom à l'enregistrement : pile ce que tu veux,

Ce format word c'est peut-être un document au format Word 2003 ou 2007 natif (.docx)
Ce format n'est pas encore à la norme Open XML et je préférère le format .doc pour l'instant et Regardes les options d'enregistrements de Word aussi pour la compatibilité avec les versions antérieures (options/ options/ onglet "Enregistrements", zone "Format par défaut ")
0
Rejoignez-nous