I'm new to Excel macros & VBA and I'm trying to invoke Shell commands from 2 buttons. They have similar functionality except for one line in them. I simply copy/pasted Button1 into another cell and modified it. The problem I'm having is that Button1 works perfectly but Button2 does nothing. When I try to modify the script for one button, the other stops working (and vice versa) and afterwards it looks like the same code is somehow copied to both buttons (not wanted). My underlying script for both buttons:
Button1 (works):
Option Explicit
Private Sub CommandButton1_Click()
Dim myFile As String, text As String, textline As String, posLat As Integer, posLong As Integer
myFile = "C:\test\source-destination.txt"
'myFile = Application.GetOpenFilename()
Dim RetVal
RetVal = Shell("C:\test\launch-this.bat", 1)
RetVal = Shell("C:\Program Files\Wireshark\tshark.exe -i ""Local Area Connection"" -a duration:10 -w c:\test\streamcapture.cap", 1)
RetVal = Shell("C:\Program Files\Wireshark\tshark.exe -r c:\test\streamcapture.cap -R ""rtmpt.handshake.c0 == 03"" -w c:\test\handshake.cap -2", 1)
RetVal = Shell("C:\Program Files\Wireshark\tshark.exe -r c:\test\handshake.cap -E separator=, -t ad > c:\test\source-destination.txt", 1)
Open myFile For Input As #1
Do Until EOF(1)
Line Input #1, textline
text = text & textline
Loop
Close #1
posLat = InStr(text, "latitude")
posLong = InStr(text, "longitude")
Range("D5").Value = Mid(text, posLat + 47, 13)
Range("E5").Value = Mid(text, posLat + 60, 14)
Range("D6").Value = Mid(text, posLat + 196, 13)
Range("E6").Value = Mid(text, posLat + 210, 14)
End Sub
/////////////////////////////////////////////////////////////////////////////
Button2 (does not react. yes I did try changing the button name in properties)
Option Explicit
Private Sub CommandButton1_Click()
Dim myFile As String, text As String, textline As String, posLat As Integer, posLong As Integer
myFile = "C:\test\source-destination.txt"
'myFile = Application.GetOpenFilename()
Dim RetVal
RetVal = Shell("C:\test\launch-this.bat", 1)
RetVal = Shell("C:\Program Files\Wireshark\tshark.exe -i ""Local Area Connection"" -a duration:10 -w c:\test\streamcapture.cap", 1)
RetVal = Shell("C:\Program Files\Wireshark\tshark.exe -r c:\test\streamcapture.cap -R ""rtmpt.handshake.c0 == 03"" -w c:\test\handshake.cap -2", 1)
RetVal = Shell("C:\Program Files\Wireshark\tshark.exe -r c:\test\handshake.cap -E separator=, -t ad > c:\test\source-destination.txt", 1)
Open myFile For Input As #1
Do Until EOF(1)
Line Input #1, textline
text = text & textline
Loop
Close #1
posLat = InStr(text, "latitude")
posLong = InStr(text, "longitude")
Range("D5").Value = Mid(text, posLat + 47, 13)
Range("E5").Value = Mid(text, posLat + 60, 14)
Range("D6").Value = Mid(text, posLat + 196, 13)
Range("E6").Value = Mid(text, posLat + 210, 14)
End Sub
Private Sub CommandButton2_Click()
End Sub
In summary, I would like to the buttons to be independent of each other since they have different functionality.
Bookmarks