Доброго времени суток!
Прошу совета, в наличие имеется код для поиска документа по части названия с последующим выводом данного документа на печать. все устраивало но появилась необходимость печать не весь документ а только 2 стр. из 3. В связи с малым знанием VBA (только начал изучать) прошу помощи или совета?
Код |
---|
Private Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long
Sub OpenAndPrint()
Dim i As Integer, FilePath As String, Paus As Long
FilePath = "E:\" 'please, insert our path to folder-source
For i = 1 To Cells(Rows.Count, "A").End(xlUp).Row
URL = Dir(FilePath & "*" & Selection.Value & "*")
'If URL = "" Then MsgBox "File NOT found", vbCritical, "": Exit Sub
URL = FilePath & URL
CreateObject("WScript.Shell").Run URL
ShellExecute 0&, vbNullString, URL, vbNullString, vbNullString, vbNormalFocus
Paus = 500 'time for delay (mS)
Delay (Paus) 'delay for open of file
SendKeys "^p", True 'insert "Ctrl+P" (Open window for print)
Paus = 600 'time for delay (mS)
Delay (Paus) 'delay for open of file
SendKeys "{Enter}", True 'insert "Enter" (Execute)
Paus = 600 'time for delay (mS)
Delay (Paus) 'delay for data communication on printer
SendKeys "%{F4}", True 'Close file
ActiveCell.Cells(2, 1).Activate
Next
End Sub
Private Sub Delay(Paus)
SStime = GetTickCount
DoEvents 'enable of the continuation of the working the main program
Do While GetTickCount - SStime < Paus: DoEvents: Loop
End Sub
|