Trevian3969
New Member
- Joined
- Jul 2, 2009
- Messages
- 3
Hi,
I have 3 columns in excel, Server, Type of connection, and IP Address
The type of connection could be WEB or RD (Remote Desktop)
I need to create a macro that could put a button in the fourth column and based on the type of connection the button will call a web browser or mstsc.exe (remote desktop connection).
It would be great if the button could be created as soon as I open the excel worksheet.
I have this code for create a button, but dont know how to pass parameters to other function
I think that the logic is fine, but couldnt test it becuase is not working
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Sub Create_button()
Dim btn As Button
Application.ScreenUpdating = False
ActiveSheet.Buttons.Delete
Dim t As Range
For i = 2 To 6 Step 1
Set t = ActiveSheet.Range(Cells(i, 4), Cells(i, 4))
Set btn = ActiveSheet.Buttons.Add(t.Left, t.Top, t.Width, t.Height)
With btn
' .OnAction = "conect" (Im stuck Here, How to pass the Type of connection and IP values to the conect sub()
' .Caption = "Conect "
.Name = "Button" & i
End With
Next i
Application.ScreenUpdating = True
End Sub
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Sub Conect(Type_connection, IP as string)
Dim retVal As Variant
Select Case Type_Connection
Case "RD"
prg = "c:\windows\system32\mstsc.exe /v:" & IP
Case "WEB"
prg = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" & IP
Case Else
GoTo 999
End Select
retVal = Shell(prg, 1)
999
End Sub</code></code></pre>
Thanks in advance
I have 3 columns in excel, Server, Type of connection, and IP Address
The type of connection could be WEB or RD (Remote Desktop)
I need to create a macro that could put a button in the fourth column and based on the type of connection the button will call a web browser or mstsc.exe (remote desktop connection).
It would be great if the button could be created as soon as I open the excel worksheet.
I have this code for create a button, but dont know how to pass parameters to other function
I think that the logic is fine, but couldnt test it becuase is not working
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Sub Create_button()
Dim btn As Button
Application.ScreenUpdating = False
ActiveSheet.Buttons.Delete
Dim t As Range
For i = 2 To 6 Step 1
Set t = ActiveSheet.Range(Cells(i, 4), Cells(i, 4))
Set btn = ActiveSheet.Buttons.Add(t.Left, t.Top, t.Width, t.Height)
With btn
' .OnAction = "conect" (Im stuck Here, How to pass the Type of connection and IP values to the conect sub()
' .Caption = "Conect "
.Name = "Button" & i
End With
Next i
Application.ScreenUpdating = True
End Sub
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Sub Conect(Type_connection, IP as string)
Dim retVal As Variant
Select Case Type_Connection
Case "RD"
prg = "c:\windows\system32\mstsc.exe /v:" & IP
Case "WEB"
prg = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" & IP
Case Else
GoTo 999
End Select
retVal = Shell(prg, 1)
999
End Sub</code></code></pre>
Thanks in advance