Option Explicit
Private Declare Function GetCommandLine Lib "kernel32" Alias "GetCommandLineA" () As Long
Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Function GetCommLine() As String
'URL: http://www.allapi.net/
Dim RetStr As Long, SLen As Long
Dim Buffer As String
RetStr = GetCommandLine
SLen = lstrlen(RetStr)
If SLen > 0 Then
GetCommLine = Space$(SLen)
CopyMemory ByVal GetCommLine, ByVal RetStr, SLen
End If
End Function
Function WBOpenByTasks() As Boolean
If InStr(1, GetCommLine, "TaskScheduler") Then
WBOpenByTasks = True
Else
WBOpenByTasks = False
End If
End Function
Function LastRow() As Long
LastRow = Worksheets("Sheet1").Cells.Find("*", SearchOrder:=xlByRows, LookIn:=xlValues, SearchDirection:=xlPrevious).Row
End Function
Sub HowOpened()
Dim LR
Dim RetVal
Dim WB
RetVal = WBOpenByTasks
LR = LastRow + 1
Worksheets("Sheet1").Cells(LR, 1) = Now
Worksheets("Sheet1").Cells(LR, 2) = WBOpenByTasks
If RetVal Then
For Each WB In Workbooks
WB.Save
Next WB
Application.Quit
End If
End Sub