2017-01-23 2 views
1

인쇄 할 문서의 일일 목록을 확인하고 매 시간마다 확인하는 인쇄 시스템을 개발하고 싶습니다.VBA : 프린터 목록

지금까지 하나의 문서를 인쇄 할 수 있었지만 시간이 더 많이 인쇄되면 첫 번째 코드 만 작동합니다.

Sub printTag() 

Dim strCommand As String 
Dim filePath As String 
Dim FileName As String 
Dim printer As String 
Dim numRefs As Integer 
Dim x As Integer 
Dim ref As String 
Dim numFiles As Integer 
Dim t As Integer 
Dim difD As Long 
Dim difH As Long 
Dim difM As Long 
Dim listDate As Date 
Dim nowDate As Date 

nowDate = ThisWorkbook.Sheets("Print").Range("B8") 
printer = ThisWorkbook.Sheets("Print").Range("B2") 
numRefs = WorksheetFunction.CountA(ThisWorkbook.Sheets("List").Columns("A")) 
numFiles = WorksheetFunction.CountA(ThisWorkbook.Sheets("Relation").Columns("A")) 

For x = 1 To numRefs 
    On Error Resume Next 
    listDate = ThisWorkbook.Sheets("List").Range("A" & x) 
    difD = DateDiff("d", nowDate, listDate) 
    If difD = 0 Then 
    difH = DateDiff("h", nowDate, listDate) 
    difM = DateDiff("n", nowDate, listDate) 
     If difH = 0 Then 
      If difM >= 0 Then 
       For t = 1 To numFiles 
        If ThisWorkbook.Sheets("List").Range("B" & x) = ThisWorkbook.Sheets("Relation").Range("A" & t) Then 
         filePath = ThisWorkbook.Sheets("Print").Range("B1") & "\" & ThisWorkbook.Sheets("Relation").Range("B" & t) 
         ThisWorkbook.Sheets("Print").Range("B3") = strCommand 
         strCommand = "PRINT " & filePath & "/D:" & printer 
         Shell strCommand, 1 
        End If 
       Next t 
      End If 
     End If 
    End If 
Next x 

End Sub 

답변

0

나는 명령 줄에서 다중 인스턴스를 보내고 완벽하게 작동하는 대신 스크립트를 만드는 아이디어를 얻었습니다. 결과는 다음과 같습니다.

Sub printTag() 

Dim strCommand As String 
Dim filePath As String 
Dim FileName As String 
Dim printer As String 
Dim numRefs As Integer 
Dim x As Integer 
Dim ref As String 
Dim numFiles As Integer 
Dim t As Integer 
Dim difD As Long 
Dim difH As Long 
Dim difM As Long 
Dim listDate As Date 
Dim nowDate As Date 

nowDate = ThisWorkbook.Sheets("Print").Range("B8") 
printer = ThisWorkbook.Sheets("Print").Range("B2") 
numRefs = WorksheetFunction.CountA(ThisWorkbook.Sheets("List").Columns("A")) 
numFiles = WorksheetFunction.CountA(ThisWorkbook.Sheets("Relation").Columns("A")) 

If Len(Dir$(ThisWorkbook.Path & "\list.bat")) > 0 Then 
    Kill ThisWorkbook.Path & "\list.bat" 
End If 
intFile = FreeFile() 
Open ThisWorkbook.Path & "\list.bat" For Output As #intFile 

For x = 1 To numRefs 
    On Error Resume Next 
    listDate = ThisWorkbook.Sheets("List").Range("A" & x) 
    difD = DateDiff("d", nowDate, listDate) 
    If difD = 0 Then 
    difH = DateDiff("h", nowDate, listDate) 
    difM = DateDiff("n", nowDate, listDate) 
     If difH = 0 Then 
      If difM >= 0 Then 
       For t = 1 To numFiles 
        If ThisWorkbook.Sheets("List").Range("B" & x) = ThisWorkbook.Sheets("Relation").Range("A" & t) Then 
         filePath = ThisWorkbook.Sheets("Print").Range("B1") & "\" & ThisWorkbook.Sheets("Relation").Range("B" & t) 
         Print #intFile, "PRINT " & filePath & " /D:" & printer 
        End If 
       Next t 
      End If 
     End If 
    End If 
Next x 
Print #intFile, "exit" 
Close #intFile 

End Sub