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
|
'Necessite d'activer la reference Microsoft Shell Controls and Automation
''''''Library Word
''''''C:\Program Files\Microsoft Office\OFFICE11\MSWORD.OLB
''''''Microsoft Word 11.0 Object Library
Sub xx()
Dim objShell As Object, strFileName As Object
Dim objFolder As Object 'Folder
Dim Resultat As String
Dim i As Byte
'///////////////////////
Dim AppWord As Word.Application
Dim myDoc As Word.Document
Dim nbPages&
'///////////////////////
Set objShell = CreateObject("Shell.Application")
'repertoire cible
Set objFolder = objShell.Namespace("C:\Test")
'boucle sur tous les elements du repertoire
For Each strFileName In objFolder.Items
'pour que les sous dossiers ne soient pas pris en comptes
If strFileName.isFolder = False Then
'///////////////////////
If LCase(Right(strFileName, 4)) = ".doc" Then
If AppWord Is Nothing Then Set AppWord = CreateObject("Word.Application")
Set myDoc = AppWord.Documents.Open("C:\Test" & "\" & strFileName & "")
nbPages& = myDoc.Windows(1).Panes(1).Pages.Count
MsgBox "Nombre de pages contenues dans ''" & strFileName & "'' : " & nbPages&
myDoc.Close wdDoNotSaveChanges
Set myDoc = Nothing
End If
End If
Next strFileName
If Not AppWord Is Nothing Then
AppWord.Quit
Set AppWord = Nothing
End If
'///////////////////////
End Sub |
Partager