+ Reply to Thread
Results 1 to 4 of 4

Change email address to hyperlink w/Macro

Hybrid View

  1. #1
    Registered User
    Join Date
    05-04-2011
    Location
    Monticello, IN
    MS-Off Ver
    Excel 2016
    Posts
    18

    Change email address to hyperlink w/Macro

    I have a workbook with several sheet within and in column ther may or may not be e-mail addresses. If there is an e-mail address I want to make it hyperlink ready, I don't want to follow it or execute just make it available to be clicked on. I have some code that I am using to loop through the book and it's sheets.

    Sub Workbook_CheckEmail()
        
        Dim Thiswb As Workbook      ' Workbook in
        Dim wks As Worksheet
        Dim rngCheck As Range          ' Input Sheet w/data
        Dim MySheet As String
        Dim MySheetCount As Integer
        Dim dtRow As Long
    
        Application.ScreenUpdating = False
    
        Set Thiswb = ActiveWorkbook
        Set rngCheck = Range("C1:C255")
        MySheetCount = 0
        dtRow = 2
    
        For Each ws In ThisWorkbook.Worksheets
        MySheet = ws.Name
            Do Until dtRow > 255
                If ws.Range("C" & dtRow).Value Like "*@*" Then
                    ws.Range("C" & dtRow).Hyperlink(1) = True
                Else
                End If
            dtRow = dtRow + 1
            Loop
        MySheetCount = MySheetCount + 1
        Next ws
        
        If MySheetCount = 0 Then
            Debug.Print "No Cell Found !!!"
        Else
        End If
        
        
        Application.ScreenUpdating = True
        
    End Sub
    Hope this help someone that can help me - thanks in advance
    Last edited by dkub; 05-26-2011 at 12:23 PM. Reason: Solved - some great help

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Change email address to hyperlink w/Macro

    dkub,

    Give this a try:
    Sub Workbook_CheckEmail()
        
        Dim wbActive As Workbook:   Set wbActive = ActiveWorkbook
        Dim rngCheck As String:     rngCheck = "C1:C255"
        Dim EmailCount As Long:     EmailCount = 0
        Dim ws As Worksheet, ThisCell As Range
        
        Application.ScreenUpdating = False
        
        For Each ws In wbActive.Worksheets
            For Each ThisCell In ws.Range(rngCheck)
                If InStr(1, ThisCell.Value, "@", vbTextCompare) > 0 Then
                    ActiveSheet.Hyperlinks.Add Anchor:=ThisCell, _
                                               Address:="mailto:" & ThisCell.Value, _
                                               TextToDisplay:=ThisCell.Value
                    EmailCount = EmailCount + 1
                End If
            Next ThisCell
        Next ws
        
        If EmailCount = 0 Then Debug.Print "No Cell Found !!!"
        
        Application.ScreenUpdating = True
        
    End Sub


    Hope this helps,
    ~tigeravatar

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Change email address to hyperlink w/Macro

    Hello dkub,

    I made a few changes to macro to add the hyperlinks for email addresses.
    Sub Workbook_CheckEmail()
        
        Dim Ccell As Range
        Dim Thiswb As Workbook      ' Workbook in
        Dim wks As Worksheet
        Dim rngCheck As Range          ' Input Sheet w/data
        Dim MySheet As String
        Dim MySheetCount As Integer
    
        Application.ScreenUpdating = False
    
        Set Thiswb = ActiveWorkbook
        MySheetCount = 0
        dtRow = 2
    
        For Each ws In ThisWorkbook.Worksheets
          MySheet = ws.Name
          Set rngCheck = ws.Range("A1:A255")
            
            For Each Cell In rngCheck
              If Cell.Value Like "*@*.*" Then
                 ws.Hyperlinks.Add Anchor:=Cell, Address:="emailto:" & Cell.Value
              End If
            Next Cell
            
          MySheetCount = MySheetCount + 1
        Next ws
        
        If MySheetCount = 0 Then
            Debug.Print "No Cell Found !!!"
        End If
        
        Application.ScreenUpdating = True
        
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Registered User
    Join Date
    05-04-2011
    Location
    Monticello, IN
    MS-Off Ver
    Excel 2016
    Posts
    18

    Re: Change email address to hyperlink w/Macro

    Thanks - bunchs they both work just fine - great help - thanks again

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1