Excel sheet with list of servers and links to different Remote Desktops

2

I have found some code to execute Remote Desktop from Excel,

Sub RDP()
    Dim RetVal As Variant
    RetVal = Shell("c:\WIndows\System32\mstsc.exe " & Range("A1"), 1)
End Sub

I have many servers to administrate, and list them as such in my excel sheet:

ServerName    DBServer                APPServer

Server 1      10.21.40.20             10.21.40.24

This list is ever expanding, I am looking for a smart way to click any of these IP's like a link in excel and execute the above RDP code.

Hope this can be done efficiently using Macros.

NxtLevel

Posted 2015-01-06T02:50:06.153

Reputation: 51

I should imagine you can achieve something like this. But tell me, what have you tried? – Dave – 2015-01-06T11:13:28.437

Have posted my solution that i've managed to create myself :) – NxtLevel – 2015-01-06T17:40:38.173

Answers

2

After much trying here's how to do it:

IP's of servers are located in column B and C, then Username and Passwords are in column D and E.

After double clicking the IP the correct username and password credentials are stored, then RDP is launched.

This is confirmed to be working!

Thanks everyone.

   Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
        Dim RetVal As Variant
        If Target.Cells.Count = 1 Then

           If Not Intersect(Target, Range("B2:B999")) Is Nothing Or Not Intersect(Target, Range("C2:C999")) Is Nothing Then
                If Not IsEmpty(Target) Then

                     RetVal = Shell("cmdkey /generic:""" & Target & """ /user:""" & Target.Offset(0, 1) & """ /pass:""" & Target.Offset(0, 2) & """", 1)
                     RetVal = Shell("c:\Windows\System32\mstsc.exe /admin /v:" & Target, 1)
                End If
            End If
        End If
    End Sub

NxtLevel

Posted 2015-01-06T02:50:06.153

Reputation: 51

I pressed Alt - F7 and put this in the window that appeared. Did I do the right thing? It didn't work for me... Could you help? – Vinayak Kaniyarakkal – 2017-05-30T09:35:09.250