将打印机数据导出为Excel并使用宏创建碳粉通知

时间:2014-07-08 19:05:04

标签: excel vba excel-vba

我在一个支持多个部门的IT办公室工作,每个部门都有一组5个以上不同的打印机。我们设置了LAN站点,显示打印机墨粉不足的情况。在我们看到低碳粉通知后,我们会根据excel电子表格重新检查打印机编号,该电子表格告诉我们哪种打印机型号以及需要哪种类型的碳粉补充。

我想知道是否可以使用excel vba整合此过程。我想运行一个宏来检查LAN站点是否有低碳粉通知,检查打印机型号并重新填充信息,然后吐出一个msgbox,说明哪些打印机需要重新填充。这将使我们免于手动点击并检查每台打印机的繁琐和单调的任务。

如果这是不可能的,那么创建一个宏来简单地显示一个msgbox,说明有多少“低碳粉”通知,这至少是件好事。

我可以提供更多细节,但我想至少先知道这样的事情是否可行。我是一名实习生,我认为可以通过excel宏解决问题,但我对他们没有经验。我只有少量的.NET编程。任何建议将不胜感激!

首先开始使用msgbox通知:

Sub InfoInputs()

    Dim strPrinterNumber As String
    Dim strTonerNumber As String

    strPrinterNumber = InputBox("Which printers are you servicing? (Please enter the full printer name i.e. ATL-15-14S220)", "Printer Selection")
    If strPrinterNumber = "" Then MsgBox "You need to enter a valid printer ID."
    Exit Sub
    End If

    If strPrinterNumber <> "" Then
        MsgBox "you chose: " & strPrinterNumber
            If strPrinterNumber = Range("E2:E30").Find(What:=strPrinterNumber, MatchCase:=True) Then
                 strTonerNumber = Range("F3:F30,G3:G30,H3:H30,I3:I30")
                MsgBox "You need: strTonerNumber"
             Else
                MsgBox "You need to enter a valid printer ID."
            End If
    End If
End Sub

1 个答案:

答案 0 :(得分:1)

Sub GetPrinterAlert()
'Get Alert from Xerox WorkCentre
    With ActiveSheet.QueryTables.Add(Connection:= _
        "URL;yourprinterurl/status/general.php", Destination:=Range("$A$1"))
        .Name = "general"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlAllTables
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
        .Refresh BackgroundQuery:=False
    End With
    'get me the total rows output
irows = Cells(Rows.Count, "B").End(xlUp).Row
'loop thru the list
For i = irows To 2 Step -1
'code that start with 09 = toner needed.
If Left(Cells(i, 2).Value, 2) <> "09" Then
'do something with this row.

'09-565-00   The Magenta Toner (M) is near end of life. User intervention is required to reorder Magenta Toner; do not replace until prompted. Machine services are unaffected.
'09-566-00   The Cyan Toner (C) is near end of life. User intervention is required to reorder Cyan Toner; do not replace until prompted. Machine services are unaffected.

End If
Next i
End Sub