Excel VBA
अभी किसी असली installation पर test नहीं किया गया — हमें बताएँ कि कैसा रहा। यह code vendor के documentation के अनुसार है। support@taskbeacon.io पर लिखें।
Task Scheduler से शुरू हुए macro के लिए; MSXML2.ServerXMLHTTP इस्तेमाल करता है। ThisWorkbook में Workbook_Open macro चलाता है और बाद में Excel बंद कर देता है, error के बाद भी, ताकि कोई Excel window इंतज़ार करती न रह जाए।
Code
यह वह code है जो Code टैब बनाता है (start, errors और rows पर निशान लगाकर)। App में इसमें पहले से आपके job का अपना पता होता है।
' --- TaskBeacon: put this in a module of the workbook (.xlsm) ---
' Task Scheduler starts Excel with the workbook; Workbook_Open (below) calls RunReport and closes Excel.
Const TB As String = "https://taskbeacon.io/ping/your-job-id"
Private Sub TbPing(ByVal path As String)
On Error Resume Next ' a failed ping must never stop the macro
Dim http As Object
Set http = CreateObject("MSXML2.ServerXMLHTTP.6.0")
http.setTimeouts 2000, 3000, 2500, 2500 ' resolve, connect, send, receive (ms): at most 10 seconds in all
http.Open "GET", TB & path, False
http.send
End Sub
Public Sub RunReport()
TbPing "/start"
On Error GoTo Failed
' --- your code here ---
ThisWorkbook.Worksheets(1).Calculate
Dim tbRows As Long
tbRows = ThisWorkbook.Worksheets(1).UsedRange.Rows.Count
TbPing "?rows=" & tbRows
Exit Sub
Failed:
Dim msg As String
msg = Left(Err.Description, 200)
TbPing "/fail?error=" & Application.WorksheetFunction.EncodeURL(msg)
End Sub
' --- TaskBeacon: put this in ThisWorkbook (not in the module) ---
' Runs when the workbook opens, then closes Excel, also after an error, so no Excel stays open.
Private Sub Workbook_Open()
On Error Resume Next ' an error in RunReport must not leave Excel waiting
RunReport
ThisWorkbook.Saved = True ' no "Save changes?" question (call ThisWorkbook.Save in RunReport to keep changes)
Application.Quit
End Subयह कैसे काम करता है
Script शुरू होने पर code /start ping करता है, ठीक से खत्म होने पर row count के साथ सादा address, और fail होने पर /fail, error के विवरण के साथ।
किसी हिस्से को छोड़ने के लिए Code टैब पर विकल्पों का निशान हटाएँ। देखें क्या रिपोर्ट किया जा सकता है।
Schedule पर चलाएँ
Task Scheduler workbook के साथ Excel शुरू करता है; Workbook_Open macro चलाता है और Excel बंद कर देता है। Start a program action के साथ एक task बनाएँ:
- Program:
EXCEL.EXEका पूरा path (Microsoft 365 के लिए आम तौर परC:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE)। - Arguments: quotes में workbook, उदाहरण के लिए
"C:\jobs\report.xlsm"।
Excel एक desktop program है: Run only when user is logged on चुनें। Signed-in user के बिना हो सकता है वह शुरू ही न हो, या किसी ऐसे dialog पर रुका रहे जिसे कोई नहीं देखता।
आम समस्याएँ
- Macro नहीं चलता। Excel उस file में macros block करता है जो internet या email से आई हो (macro की जगह security banner दिखता है)। File पर right-click → Properties → Unblock पर tick करें, या उसे Trusted Location में रखें (File → Options → Trust Center → Trust Center Settings → Trusted Locations)। Company policy फिर भी उसे block कर सकती है; तब IT से पूछें।
- Workbook हाथ से खोलने पर macro चल जाता है और Excel बंद हो जाता है। यह
Workbook_Openका काम है। Workbook edit करने के लिए उसे खोलते समय Shift दबाए रखें (File → Open → Browse, Shift दबाए रखें और Open पर click करें; Recent list से खोलने पर Shift का कोई असर नहीं होता)। - Excel खुला रह जाता है। कोई dialog इंतज़ार कर रहा है, जैसे Update links? या आपके code में कोई message box। Dialog हटाएँ या code में उसका जवाब दें।
- कोई ping नहीं। Ping ज़्यादा से ज़्यादा 10 seconds इंतज़ार करता है; HTTPS को block करने वाला proxy या firewall macro को हाथ से चलाने पर पता चल जाता है।
उपयोग के उदाहरण: Task Scheduler से चलने वाले Excel VBA macro को monitor करें। और सवाल: FAQ.