Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Word > VBA Word
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 15/11/2006, 14h55   #1
Membre habitué
 
Inscription : janvier 2006
Messages : 344
Détails du profil
Informations forums :
Inscription : janvier 2006
Messages : 344
Points : 116
Points : 116
Par défaut Comment ouvrir word depuis macro excel ?

bonjour,

j'ai crée une macro ou :

1) je saisis le chemin du repertoire ou il y a plein des fichiers *.doc
2) et je parcours le repertoire et les fichiers et je mets le nom des fichiers dans excel (boucle)

jusqu'ici tout ce passe bien

3) en suite je dois ouvrir le fichier word en cours (boucle 2) ) et recupere le nbpage du doc puis le fermer

et la j'ai un erreur du type

Code :
1
2
3
 
 
user-defined type not defined
voici le code de ma macro ( macro excel ) :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
 
 
'======================================================'
'= the user paste the paste of folder and push button ='
'= the macro find doc file  in the folder             ='
'= each name of file is listed in excel sheet         ='
'=                                                    ='
'======================================================'
 
Option Explicit
 
Public folderinput As String
Public rep As String
Public nbpage As Integer
 
Public Sub btnlist_Click()
 
Dim celex As String
Dim i As Integer
 
folderinput = txtfolder.Value
Debug.Print folderinput
 
i = 1
 
'path folder to parse
rep = Dir(folderinput & "\*.doc", vbDirectory)
 
'loop while not end of folder et <>empty
Do While (rep <> "")
 
    If (GetAttr(folderinput & "\" & rep)) <> vbDirectory Then
 
         Debug.Print rep
 
         celex = Left(Right(rep, 14), 10)
         Debug.Print celex
 
         If IsNumeric(Left(celex, 5)) Then
 
         Cells(i, 1).Value = celex
 
         Call OpenDocument
 
         Cells(i, 2).Value = nbpage
 
         i = i + 1
 
         End If
 
 
 
    End If
 
    'next file
    rep = Dir
 
Loop
 
MsgBox ("There is/are " & i & " files ")
 
 
End Sub
 
 
Sub OpenDocument()
Dim appwd As Word.Application
Dim wordfile As String
 
  wordfile = folderinput & "\" & rep
  Debug.Print wordfile
 
  Set appwd = CreateObject("Word.Application")
  With appwd
      .WordBasic.DisableAutoMacros 1 '0 pour activer
      .Visible = True
      .Documents.Open wordfile
      .Activate
 
  End With
 
  nbpage = ActiveDocument.Range.Information(wdActiveEndPageNumber)
  Debug.Print nbpage
 
  appwd.Documents.Close
 
End Sub
donc voici l'endroit ou il y a l'erreur :

Code :
1
2
3
4
5
6
7
8
 
 
Call OpenDocument
 
 
puis ici :
 
Dim appwd As Word.Application

je ne sais pas pourquoi il y a une erreur , j'ai regardé dans la faq


si une âme charitable pouvait m'aider

merci
megapacman est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/11/2006, 15h33   #2
Inactif
 
Avatar de ouskel'n'or
 
Inscription : février 2005
Messages : 12 466
Détails du profil
Informations forums :
Inscription : février 2005
Messages : 12 466
Points : 11 930
Points : 11 930
Tiens, regarde là, http://www.developpez.net/forums/sho...ght=Word+Excel SilkyRoad fournit plein de renseignements intéressants
Sinon, regarde dans la faq ou fais une recherche sur le forum VBA, le sujet a été traité nnnnnnnnn fois
ouskel'n'or est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/11/2006, 15h44   #3
Membre habitué
 
Inscription : janvier 2006
Messages : 344
Détails du profil
Informations forums :
Inscription : janvier 2006
Messages : 344
Points : 116
Points : 116
merci en fait , en regardant ton lien avec les posts

j'ai remarqué que dans tools reference j'avais pas coché µsoft word

ca fonctionne presque


maintenant il reste bloqué à :

Code :
1
2
3
4
 
 
 nbpage = ActiveDocument.Range.Information(wdActiveEndPageNumber)
  Debug.Print nbpage

en fait ici : ActiveDocument c'est le doc word en cours que je veux spécifié et non le fichier excel


comment le spécifié ?

merci
megapacman est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/11/2006, 15h44   #4
Responsable Visual Basic
 
Avatar de bbil
 
Inscription : juin 2003
Messages : 11 773
Détails du profil
Informations personnelles :
Âge : 45
Localisation : France, Ariège (Midi Pyrénées)

Informations forums :
Inscription : juin 2003
Messages : 11 773
Points : 16 854
Points : 16 854
Envoyer un message via Skype™ à bbil
Citation:
Envoyé par FAQ
Nécessite d'activer la référence "Microsoft Word xx.x Object Library".
Manipuler WORD


voir :
Code :
1
2
3
4
dim wd as Word.Document 
....
 set wd =  .Documents.Open (wordfile)
....
puis utilise wd en lieu et place de active document
bbil est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/11/2006, 15h59   #5
Membre habitué
 
Inscription : janvier 2006
Messages : 344
Détails du profil
Informations forums :
Inscription : janvier 2006
Messages : 344
Points : 116
Points : 116
ok ca fonctionne comme ca maintenant

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
 
Sub OpenDocument()
Dim appwd As Word.Application
Dim wordfile As String
 
  wordfile = folderinput & "\" & rep
  Debug.Print wordfile
 
  Set appwd = CreateObject("Word.Application")
  With appwd
      .WordBasic.DisableAutoMacros 1 '0 pour activer
      .Visible = True
      .Documents.Open wordfile
      .Activate
 
        nbpage = ActiveDocument.Range.Information(wdActiveEndPageNumber)
        Debug.Print nbpage
 
  End With
 
  appwd.Documents.Close
 
End Sub

merci
megapacman est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 07h08.


 
 
 
 
Partenaires

Hébergement Web