14 ms·
https://pastebin.com/2MEKNGx5 https://pastebin.com/2MEKNGx5 This is an Excel macro that is self-aware: it only tries to print itself if it is a quine. It's se
by perl4ever 5y ago
https://pastebin.com/2MEKNGx5 https://pastebin.com/2MEKNGx5
This is an Excel macro that is self-aware: it only tries to print itself if it is a quine.
It's sensitive to whitespace, so I provided the pastebin link above.
Sub selfCheckingExcelQuine()
s = "Sub selfCheckingExcelQuine()\ s = ~\ result = Replace(Replace(Replace(s, Chr(36), Chr(34)), Chr(92), vbCrLf), Chr(126), Chr(34) & s & Chr(34))\ \ If myText() = result Then\ Debug.Print result\ Else\ Debug.Print $Not a quine!$\ End If\End Sub\\Function myText()\ Dim p As VBProject: Set p = ThisWorkbook.VBProject\ Dim m As CodeModule: Set m = p.VBComponents(p.VBE.SelectedVBComponent.Name).CodeModule\ \ myText = m.Lines(1, m.CountOfLines)\End Function\"
result = Replace(Replace(Replace(s, Chr(36), Chr(34)), Chr(92), vbCrLf), Chr(126), Chr(34) & s & Chr(34))
If myText() = result Then
Debug.Print result
Else
Debug.Print "Not a quine!"
End If
End Sub
Function myText()
Dim p As VBProject: Set p = ThisWorkbook.VBProject
Dim m As CodeModule: Set m = p.VBComponents(p.VBE.SelectedVBComponent.Name).CodeModule
myText = m.Lines(1, m.CountOfLines)
End Function