- 'n'oubliez pas de changer la constante file en fonction de votre système :o)
- Const file As Variant = "D:\test.doc"
-
- Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
- Private Declare Function FindExecutableA Lib "shell32.dll" (ByVal lpFile As String, ByVal lpdirectory As String, ByVal lpResult As String) As Long
- Private Const MAX_FILENAME_LEN = 256
-
- Private Sub Command1_Click()
- On Error Resume Next
- 'détermine le chemin d'accès de Word
- Dim app
- app = FindExecutable(file)
- 'lance word
- Shell app & " " & file
- 'imprime le doc avec les paramètres par défaut
- 'cliquez sur printout puis appuyez sur F1 pour + d'infos
- Word.ActiveDocument.PrintOut
- 'stoppe toutes les activités de l'appli pendant 5 sec. pour éviter tout pb
- Sleep (5000)
- 'ferme Word
- Word.Application.Quit
- End Sub
-
- Public Function FindExecutable(s As String) As String
- Dim i As Integer
- Dim s2 As String
- s2 = String(MAX_FILENAME_LEN, 32) & Chr$(0)
- i = FindExecutableA(s & Chr$(0), vbNullString, s2)
- If i > 32 Then
- FindExecutable = Left$(s2, InStr(s2, Chr$(0)) - 1)
- Else
- FindExecutable = ""
- End If
- End Function
-
- Private Sub Command2_Click()
- On Error Resume Next
- 'détermine le chemin d'accès de Word
- Dim app
- app = FindExecutable(file)
- 'lance word
- Shell app & " " & file
- 'imprime le doc avec les paramètres par défaut
- 'cliquez sur printout puis appuyez sur F1 pour + d'infos
- Word.Application.Dialogs(wdDialogFilePrint).Show
- 'quitte word
- Word.Application.Quit
- End Sub
-
- Private Sub Command3_Click()
- MsgBox "je ne suis pas arrivé à établir une liaison DDE avec Word", vbExclamation
- End Sub
-
- Private Sub Form_Load()
- Me.Height = 2460
- Me.Width = 4050
- Me.Caption = "comment imprimer un .doc ?"
- With Command1
- .Height = 320
- .Width = 3375
- .Left = 240
- .Top = 480
- .Caption = "par l'objet Word sans intervention utilisateur"
- End With
- With Command2
- .Height = 320
- .Width = 3375
- .Left = 240
- .Top = 960
- .Caption = "par l'objet Word avec intervention utilisateur"
- End With
- With Command3
- .Height = 320
- .Width = 3375
- .Left = 240
- .Top = 1440
- .Caption = "par liaison dde"
- End With
- End Sub
-
'n'oubliez pas de changer la constante file en fonction de votre système :o)
Const file As Variant = "D:\test.doc"
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function FindExecutableA Lib "shell32.dll" (ByVal lpFile As String, ByVal lpdirectory As String, ByVal lpResult As String) As Long
Private Const MAX_FILENAME_LEN = 256
Private Sub Command1_Click()
On Error Resume Next
'détermine le chemin d'accès de Word
Dim app
app = FindExecutable(file)
'lance word
Shell app & " " & file
'imprime le doc avec les paramètres par défaut
'cliquez sur printout puis appuyez sur F1 pour + d'infos
Word.ActiveDocument.PrintOut
'stoppe toutes les activités de l'appli pendant 5 sec. pour éviter tout pb
Sleep (5000)
'ferme Word
Word.Application.Quit
End Sub
Public Function FindExecutable(s As String) As String
Dim i As Integer
Dim s2 As String
s2 = String(MAX_FILENAME_LEN, 32) & Chr$(0)
i = FindExecutableA(s & Chr$(0), vbNullString, s2)
If i > 32 Then
FindExecutable = Left$(s2, InStr(s2, Chr$(0)) - 1)
Else
FindExecutable = ""
End If
End Function
Private Sub Command2_Click()
On Error Resume Next
'détermine le chemin d'accès de Word
Dim app
app = FindExecutable(file)
'lance word
Shell app & " " & file
'imprime le doc avec les paramètres par défaut
'cliquez sur printout puis appuyez sur F1 pour + d'infos
Word.Application.Dialogs(wdDialogFilePrint).Show
'quitte word
Word.Application.Quit
End Sub
Private Sub Command3_Click()
MsgBox "je ne suis pas arrivé à établir une liaison DDE avec Word", vbExclamation
End Sub
Private Sub Form_Load()
Me.Height = 2460
Me.Width = 4050
Me.Caption = "comment imprimer un .doc ?"
With Command1
.Height = 320
.Width = 3375
.Left = 240
.Top = 480
.Caption = "par l'objet Word sans intervention utilisateur"
End With
With Command2
.Height = 320
.Width = 3375
.Left = 240
.Top = 960
.Caption = "par l'objet Word avec intervention utilisateur"
End With
With Command3
.Height = 320
.Width = 3375
.Left = 240
.Top = 1440
.Caption = "par liaison dde"
End With
End Sub