i want to write a macro on ubuntu LibraOffice and ping a specific cell which contain a valid ip address.
This macro:
Sub shellTest
oSheet=ThisComponent.CurrentController.ActiveSheet
Cell = oSheet.GetCellRangeByName("A1")
ipAddr = Cell.getString
Shell ("exo-open --launch TerminalEmulator ping -c 5 " & ipAddr)
End Sub
reads the value in ‘A1’ on the current sheet and attempts to ping the address in that cell 5 times.
Hi! I need to take the results of this ping and take it in a cell:
in windows i can do this:
Set objshell = CreateObject(“Wscript.Shell”)
boolcode = objshell.Run("ping -n 1 -w 1000 " & strip, 0, 1)
where boolcode is the result of the ping and strip is the ip to ping.
how can i do this on linux?
here is all my code:
Rem Attribute VBA_ModuleType=VBAModule
Option VBASupport 1
Function CheckOS()
Dim CheckOSO As String
CheckOS = Null
CheckOSO = Application.OperatingSystem
If InStr(1, LCase(CheckOSO), "windows") <> 0 Then
CheckOS = True
Else
CheckOS = False
End If
End Function
Function Ping(strip)
Dim objShell, boolcode
Ping = Null
boolcode = 3
If CheckOS = True Then
Set objshell = CreateObject(“Wscript.Shell”)
boolcode = objshell.Run("ping -n 1 -w 1000 " & strip, 0, 1)
Else
'put here the linux instructions to ping
End If
If boolcode = 0 Then
Ping = True
Else
If boolcode = 1 Then
Ping = False
Else
Ping = Null
End If
End If
End Function
Sub PingSystem()
Dim strip As String
Do Until Worksheets(“VMs”).Range(“D1”).Value = “STOP”
Worksheets(“VMs”).Range(“D1”).Value = “TESTING”
For introw = 3 To Worksheets(“VMs”).Cells(Rows.Count, 16).End(xlUp).Row
strip = Worksheets(“VMs”).Cells(introw, 16).Value
If Ping(strip) = True Then
Worksheets(“VMs”).Cells(introw, 4).Interior.Color = RGB(254, 254, 160)
Worksheets(“VMs”).Cells(introw, 4).Font.Color = RGB(0, 0, 0)
Worksheets(“VMs”).Cells(introw, 4).Value = “y”
‘Application.Wait (Now + TimeValue(“0:00:01”))’
Worksheets(“VMs”).Cells(introw, 4).Font.Color = RGB(0, 200, 0)
Worksheets(“VMs”).Cells(introw, 4).Interior.Color = RGB(223, 236, 212)
Else
If Ping(strip) = False Then
Worksheets(“VMs”).Cells(introw, 4).Interior.Color = RGB(254, 254, 160)
Worksheets(“VMs”).Cells(introw, 4).Font.Color = RGB(0, 0, 0)
Worksheets(“VMs”).Cells(introw, 4).Value = “n”
‘Application.Wait (Now + TimeValue(“0:00:01”))’
Worksheets(“VMs”).Cells(introw, 4).Font.Color = RGB(200, 0, 0)
Worksheets(“VMs”).Cells(introw, 4).Interior.Color = RGB(252, 174, 148)
Else
Worksheets(“VMs”).Cells(introw, 4).Interior.Color = RGB(254, 254, 160)
Worksheets(“VMs”).Cells(introw, 4).Font.Color = RGB(0, 0, 0)
Worksheets(“VMs”).Cells(introw, 4).Value = “err”
‘Application.Wait (Now + TimeValue(“0:00:01”))’
Worksheets(“VMs”).Cells(introw, 4).Font.Color = RGB(200, 0, 0)
Worksheets(“VMs”).Cells(introw, 4).Interior.Color = RGB(252, 174, 148)
End If
End If
If Worksheets(“VMs”).Range(“D1”).Value = “STOP” Then
Exit For
End If
Next
Worksheets(“VMs”).Range(“D1”).Value = “STOP”
Loop
Worksheets(“VMs”).Range(“D1”).Value = “IDLE”
End Sub
Sub stop_ping()
Worksheets(“VMs”).Range(“D1”).Value = “STOP”
End Sub
This should be a new question.
I avoid VBA now since I hardly used it in many years now.
ok I have opened a new topic