Jump to content

Recommended Posts

Posted

Hi all, I hope there is a VBA script wizard that can help me with this.

 

I have a spreadsheet containing a list of servers and their IPs. Each server has a sub-workbook where I am tracking daily/weekly resource usage for capacity planning purposes (long story). I need to do the following:

 

In the column containing the IP addresses, I need to format the IP address into a hyperlink that, when clicked, automatically launches MSTSC with the /admin permissions.

 

So the command line command would be

 

mstsc /v:111.222.333.444:3389 /admin

 

I have done a web search and found various solutions that use the 'reference active cell' but a) can't seem to get these to work and b) I have to hotkey them to get them to operate and this spreadsheet will be shared with other technicians in the department - I don't want to have to train everyone on how to use it. I just want them to be able to click on the RDP link and RDP will open and prompt for Creds (or if they already have them saved for that machine, it will just go through automatically).

 

I'm afraid I know almost nothing about writing VB scripts or macros. It's not the end of the world if we can't do it but I've seen it done before so I'm pretty sure it's possible, it's just waaaaaay beyond my meagre abilities.

 

Thanks in advance.

Posted

After posting this, I refined my search more and found the following from HERE which seems to do the trick:

 

Private Sub Worksheet_Change(ByVal Target As Range)


' Create_Hyperlinks()
    
   Dim c As Variant
   Dim my_range As Range
    
   With ActiveSheet
       If Not Intersect(Target, .Columns("B")) Is Nothing Then
       
            'adapt this line below to suit your needs - it creates a hyperlink out of entries in column B
           Set my_range = .Range("B2:B" & .Range("B" & Rows.Count).End(xlUp).Row)
           For Each c In my_range
               If Trim(c.Value) <> "" Then
                   .Hyperlinks.Add Anchor:=Range(c.Address), Address:="", SubAddress:=c.Address, TextToDisplay:=c.Value
               End If
           Next c
       End If
   End With
   
End Sub

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
    
   Dim RetVal
    
    
   RetVal = Shell("c:\windows\system32\mstsc.exe /v:" & Target.Name, 1)
    
End Sub

Posted
However, the problem I have with this is that in Column B I have a list of server names I want to link to other worksheets within the workbook, BUT when I create hyperlinks to other parts of the document, I click on the server name and the workbook jumps to the location in the document (GREAT) BUT also opens RDP with the server name (NOT GREAT). I have specified my cell range in the Column C macro so I don't know why it's applying to column B too :-(

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...