Results 1 to 32 of 32

Thread: remove hyperlinks

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    151

    remove hyperlinks

    I am trying to remove hyperlink from excel sheet.

    I am able to remove hyperlink from auto shapes like callouts, arrow...

    its working for images also.

    only hyperlinks from organization chart is not goin....



    if u see code given below... its not counting the hyperlinks in the organization chart.. i.e. they r not deleted...



    Code:
    MsgBox (wSheet.Hyperlinks.Count)
                            For i = wSheet.Hyperlinks.Count To 1 Step -1
                                
                                If cancelPwd = True Then
                                   Exit For
                                End If
    
                                If wSheet.Hyperlinks(i).Type <> 0 Then
                                  wSheet.Hyperlinks(i).Delete
                                  ObjExcel.Save
                                End If
                            Next i

  2. #2
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: remove hyperlinks

    You will need to select the shape itself in code and then remove the link from within the shape, it will not show up on the hyperlinks in the spreadsheet..

    VB Code:
    1. ActiveSheet.Shapes("Organization Chart").Select
    2. Selection.ShapeRange.Item(1).Hyperlink.Delete 'Change to the item number or name
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    151

    Re: remove hyperlinks

    but then i have to explicitely give this for every graphical object..
    dont u think?

    is there a groupname for all the graphical objects which i can give? which i can give ..... like i can replace organization chart with that name....

    ActiveSheet.Shapes("Organization Chart").Select
    Selection.ShapeRange.Item(1).Hyperlink.Delete 'Change to the item number or name

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    151

    Re: remove hyperlinks

    the code snippet given by u is not working...
    have u checked it anytime?

  5. #5
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: remove hyperlinks

    It was what was showed up on a recorded macro.. trying to run it a second time fails to work, there will be another way..
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    151

    Re: remove hyperlinks

    its not working for the first time also

  7. #7
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: remove hyperlinks

    Okay.. This is what I found out.. seems a bit overkill but it does do the job..

    VB Code:
    1. Dim Shp As ShapeRange
    2.   Dim IShp As Shape
    3.   Dim i As Integer
    4.   Dim j As Integer
    5.   For i = 1 To ActiveSheet.Shapes.Count
    6.     ActiveSheet.Shapes(1).Select
    7.     Set Shp = Selection.ShapeRange
    8.     For j = 1 To Shp.DiagramNode.Diagram.Nodes.Count
    9.       Set IShp = Shp.DiagramNode.Diagram.Nodes(j).Shape
    10.       On Error Resume Next
    11.       If IShp.Hyperlink.Address <> "" Then
    12.         IShp.Hyperlink.Delete
    13.       End If
    14.       On Error GoTo 0
    15.     Next j
    16.   Next i
    17. End Sub

    Not tested on a shape without any subsequent shapes inside, so not sure what will happen, but this should remove the hyperlinks from all organisation charts on the spreadsheet.
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    151

    Re: remove hyperlinks

    its also not working....

    bye d way where do u got the code from?

  9. #9
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: remove hyperlinks

    It might not work in the loop try taking it out of the loop and refer to the organization chart explicity..

    The code came from my own head.. as always..

    Try this one

    VB Code:
    1. Dim Shp As ShapeRange
    2.   Dim IShp As Shape
    3.   Dim i As Integer
    4.   ActiveSheet.Shapes("Name of Organization chart here").Select
    5.   Set Shp = Selection.ShapeRange
    6.   For i = 1 To Shp.DiagramNode.Diagram.Nodes.Count
    7.     Set IShp = Shp.DiagramNode.Diagram.Nodes(i).Shape
    8.     On Error Resume Next
    9.     If IShp.Hyperlink.Address <> "" Then
    10.       IShp.Hyperlink.Delete
    11.     End If
    12.     On Error GoTo 0
    13.   Next i
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    151

    Re: remove hyperlinks

    Code:
    If IShp.Hyperlink.Address <> "" Then
    IShp.Hyperlink.Delete
    method or data member not found....

    No one seems to have such problem anytime?

  11. #11
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: remove hyperlinks

    Sorry my bad the error trapping doesn't work all that good.. this sub will remove all hyperlinks, in shapes, orgcharts and cells in the activesheet.

    VB Code:
    1. Sub removelinks()
    2.   Dim Shp As ShapeRange
    3.   Dim IShp As Shape
    4.   Dim i As Integer
    5.   Dim j As Integer
    6.   On Error GoTo ResNextShp
    7.   For j = 1 To ActiveSheet.Shapes.Count
    8.     ActiveSheet.Shapes(j).Select
    9.     Set Shp = Selection.ShapeRange
    10.     If Shp.HasDiagramNode = msoTrue Then
    11.       For i = 1 To Shp.DiagramNode.Diagram.Nodes.Count
    12.         Set IShp = Shp.DiagramNode.Diagram.Nodes(i).Shape
    13.         If IShp.Hyperlink.Address <> "" Then
    14.           IShp.Hyperlink.Delete
    15.         End If
    16.       Next i
    17.     Else
    18.       Set IShp = ActiveSheet.Shapes(j)
    19.       If IShp.Hyperlink.Address <> "" Then IShp.Hyperlink.Delete
    20.     End If
    21.   Next j
    22.   Debug.Print ActiveSheet.Hyperlinks.Count
    23.   i = 0
    24.   For i = ActiveSheet.Hyperlinks.Count To 1 Step -1
    25.     ActiveSheet.Hyperlinks(i).Delete
    26.   Next i
    27.   Exit Sub
    28.  
    29. ResNextShp:
    30.   Resume Next
    31. End Sub
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    151

    Re: remove hyperlinks

    Code:
    If IShp.Hyperlink.Address <> "" Then
    IShp.Hyperlink.Delete
    method or data member not found

  13. #13
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: remove hyperlinks

    Are you using the exact code that I gave you as it seems to be turning the error trap off..

    I have tested this on a spreadsheet with an organisation chart, two objects with a hyperlink, a block arrow again with a hyperlink and then to cells in the file with hyperlinks... post the exact code you are using..
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    151

    Re: remove hyperlinks

    [code]

    Dim objexcel As Excel.Application
    Dim objworksheet As Excel.Worksheet
    Dim objworkbook As Excel.Workbooks

    Private Sub cmddelete_Click()
    Set objexcel = CreateObject("Excel.Application")
    objexcel.Workbooks.Open ("c:\Book1.xls")
    objexcel.WindowState = xlMinimized
    objexcel.WindowState = xlMaximized


    Dim Shp As ShapeRange
    Dim IShp As Shape
    Dim i As Integer
    Dim j As Integer
    On Error GoTo ResNextShp
    For j = 1 To ActiveSheet.Shapes.Count
    ActiveSheet.Shapes(j).Select
    Set Shp = Selection.ShapeRange
    If Shp.HasDiagramNode = msoTrue Then
    For i = 1 To Shp.DiagramNode.Diagram.Nodes.Count
    Set IShp = Shp.DiagramNode.Diagram.Nodes(i).Shape
    If IShp.Hyperlink.Address <> "" Then
    IShp.Hyperlink.Delete
    End If
    Next i
    Else
    Set IShp = ActiveSheet.Shapes(j)
    If IShp.Hyperlink.Address <> "" Then IShp.Hyperlink.Delete
    End If
    Next j
    Debug.Print ActiveSheet.Hyperlinks.Count
    i = 0
    For i = ActiveSheet.Hyperlinks.Count To 1 Step -1
    ActiveSheet.Hyperlinks(i).Delete
    Next i
    Exit Sub

    ResNextShp:
    Resume Next

    End Sub




    [code]

  15. #15
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: remove hyperlinks

    That explains it then.. you are not doing this within Excel, but rather vb6 to excel ??

    VB Code:
    1. Dim objexcel As Excel.Application
    2. Dim objworksheet As Excel.Worksheet
    3. Dim objworkbook As Excel.Workbooks
    4.  
    5. Private Sub cmddelete_Click()
    6.   Set objexcel = CreateObject("Excel.Application")
    7.   objexcel.Workbooks.Open ("c:\Book1.xls")
    8.   objexcel.WindowState = xlMinimized
    9.   objexcel.WindowState = xlMaximized
    10.   Dim Shp As Excel.ShapeRange
    11.   Dim IShp As Excel.Shape
    12.   Dim i As Integer
    13.   Dim j As Integer
    14.   On Error GoTo ResNextShp
    15.   For j = 1 To objexcel.ActiveSheet.Shapes.Count
    16.     objexcel.ActiveSheet.Shapes(j).Select
    17.     Set Shp = Selection.ShapeRange
    18.     If Shp.HasDiagramNode = msoTrue Then
    19.       For i = 1 To Shp.DiagramNode.Diagram.Nodes.Count
    20.         Set IShp = Shp.DiagramNode.Diagram.Nodes(i).Shape
    21.         If IShp.Hyperlink.Address <> "" Then IShp.Hyperlink.Delete
    22.       Next i
    23.     Else
    24.       Set IShp = objexcel.ActiveSheet.Shapes(j)
    25.       If IShp.Hyperlink.Address <> "" Then IShp.Hyperlink.Delete
    26.     End If
    27.   Next j
    28.   i = 0
    29.   For i = objexcel.ActiveSheet.Hyperlinks.Count To 1 Step -1
    30.     objexcel.ActiveSheet.Hyperlinks(i).Delete
    31.   Next i
    32.   Exit Sub
    33.  
    34. ResNextShp:
    35.   Resume Next
    36. End Sub
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    151

    Re: remove hyperlinks

    Hi !
    I have tried the code in excel, it is removing all hyperlinks except organization chart.
    Which i have already done.

    Actually i am creating a activex control in vb which will remove all the links from selected excel sheet except a text link.

    I have developed code for this. Only problem is with the organization chart (or u can say graphical objects)

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    151

    Re: remove hyperlinks

    HI !

    First of all thanks for being with me...

    I have tried this code in vb it's not givin any error and also removing hyperlinks but not from organization chart.

  18. #18
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: remove hyperlinks

    The organization chart works with shape nodes, shapes within an existing shape.. The code will remove hyperlinks from the shapes inside the organization chart, if there is a hyperlink on the organization chart itself then it will be best to include it at the end of the first loop..

    Change the If..Else..End If statement so that it will refer to the organization chart as an object straight after removing any links from it's nodes..

    VB Code:
    1. Dim objexcel As Excel.Application
    2. Dim objworksheet As Excel.Worksheet
    3. Dim objworkbook As Excel.Workbooks
    4.  
    5. Private Sub cmddelete_Click()
    6.   Set objexcel = CreateObject("Excel.Application")
    7.   objexcel.Workbooks.Open ("c:\Book1.xls")
    8.   objexcel.WindowState = xlMinimized
    9.   objexcel.WindowState = xlMaximized
    10.   Dim Shp As Excel.ShapeRange
    11.   Dim IShp As Excel.Shape
    12.   Dim i As Integer
    13.   Dim j As Integer
    14.   On Error GoTo ResNextShp
    15.   For j = 1 To objexcel.ActiveSheet.Shapes.Count
    16.     objexcel.ActiveSheet.Shapes(j).Select
    17.     Set Shp = Selection.ShapeRange
    18.     If Shp.HasDiagramNode = msoTrue Then
    19.       For i = 1 To Shp.DiagramNode.Diagram.Nodes.Count
    20.         Set IShp = Shp.DiagramNode.Diagram.Nodes(i).Shape
    21.         If IShp.Hyperlink.Address <> "" Then IShp.Hyperlink.Delete
    22.       Next i
    23.     End If
    24.     Set IShp = objexcel.ActiveSheet.Shapes(j)
    25.     If IShp.Hyperlink.Address <> "" Then IShp.Hyperlink.Delete
    26.   Next j
    27.   i = 0
    28.   For i = objexcel.ActiveSheet.Hyperlinks.Count To 1 Step -1
    29.     objexcel.ActiveSheet.Hyperlinks(i).Delete
    30.   Next i
    31.   Exit Sub
    32.  
    33. ResNextShp:
    34.   Resume Next
    35. End Sub

    This can also be re-coded to remove from all sheets by inserting a couple more lines as a loop around the worksheets, if you want that as well then let me know.
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  19. #19

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    151

    Re: remove hyperlinks

    Hi ! I have used above given code but its not working.
    can u just check if its working?

    You want me to make any changes in ur code?
    Attached Files Attached Files

  20. #20
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: remove hyperlinks

    Unfotunately I had to leave office early yesterday. I have had a look at the process and it does not remove the link from the Organisation Chart itself, but why would the actual chart have a link anyway? Do the individual names in the chart have the links??

    I will have to look into this a bit more as even the recorded macro method does work..

    I cannot use vb6 at work, only have .Net and office.
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  21. #21

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    151

    Re: remove hyperlinks

    HI ! How was ur yesdy?
    I hope it was great.....

    not individuals names in org. chart has hyperlinks. But the lines inside org. chart has links. ALso links are there on a org. chart itself.

    have a good day!

  22. #22
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: remove hyperlinks

    ActiveSheet.Hyperlinks.Count always returns ZERO for me in Excel '97 and 2003. There are TWO working hyperlinks on the sheet. You might start a new thread asking how to detect hyperlinks.
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  23. #23
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: remove hyperlinks

    This might help:
    Code:
    Sub Macro1()
    ' Select a cell and run this macro
    ' If more than one cell is selected, only the upper left cell is tested
    Dim i As Integer
    
        i = InStr(Selection.Formula, "HYPERLINK")
        If i > 0 Then MsgBox "This is probably a HYPERLINK cell"
    End Sub
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  24. #24

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    151

    Re: remove hyperlinks

    I dont want to remove text hyperlinks :

    can u just modify this code?


    VB Code:
    1. Dim nolinks As Integer
    2.   nolinks = 0
    3.   Dim Shp As Excel.ShapeRange
    4.   Dim IShp As Excel.Shape
    5.   Dim i As Integer
    6.   Dim j As Integer
    7.   On Error GoTo ResNextShp
    8.   If wSheet.Hyperlinks.Count = 0 Then
    9.      nolinks = nolinks + 1
    10.   Else
    11.                  
    12.        
    13.   For j = 1 To AppExcel.ActiveSheet.Shapes.Count
    14.     AppExcel.ActiveSheet.Shapes(j).Select
    15.     Set Shp = Selection.ShapeRange
    16.     If Shp.HasDiagramNode = msoTrue Then
    17.       For i = 1 To Shp.DiagramNode.Diagram.Nodes.Count
    18.         Set IShp = Shp.DiagramNode.Diagram.Nodes(i).Shape
    19.         If IShp.Hyperlink.Address <> "" Then
    20.         IShp.Hyperlink.Delete
    21.         hashyperlinks = True
    22.         End If
    23.       Next i
    24.     End If
    25.     Set IShp = AppExcel.ActiveSheet.Shapes(j)
    26.     If IShp.Hyperlink.Address <> "" Then
    27.     IShp.Hyperlink.Delete
    28.     hashyperlinks = True
    29.     'End If
    30.     End If
    31.   Next j
    32.  
    33.  
    34.   i = 0
    35.   For i = AppExcel.ActiveSheet.Hyperlinks.Count To 1 Step -1
    36.     AppExcel.ActiveSheet.Hyperlinks(i).Delete
    37.     hashyperlinks = True
    38.  
    39.   Next i
    40.  
    41.  
    42. 'End If
    43. ResNextShp:
    44.   Resume Next

  25. #25
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: remove hyperlinks

    "Re: remove hyperlinks"
    "I am trying to remove hyperlink from excel sheet."

    "I dont want to remove text hyperlinks :"

    ???? Make up your mind please.

    "can u just modify this code?"

    No
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  26. #26
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: remove hyperlinks

    My Comment:
    Quote Originally Posted by Webtest
    ActiveSheet.Hyperlinks.Count always returns ZERO for me in Excel '97 and 2003.
    Your Code:
    Code:
      For i = AppExcel.ActiveSheet.Hyperlinks.Count To 1 Step -1
        AppExcel.ActiveSheet.Hyperlinks(i).Delete
        hashyperlinks = True
      Next i
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  27. #27
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: remove hyperlinks

    Art,

    the code is mine.. v_gyku wants all hyperlinks removing from the sheet, this includes those inside cells, those on shapes and also those on diagrams.

    the code I gave him did this, however it would not remove the links on an organization chart itself.

    I can't find a way easily to do this, and at present I do not have the time to go back to this.

    I will come back with other solutions as and when my current workload eases up.
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  28. #28
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: remove hyperlinks

    Danny ...

    You have more patience and time than I do. He ought to break out the smallest piece of code that doesn't work. I just don't have time to scrounge through a bunch of uncommented code looking for subtle operational problems.

    I don't think the piece of code I highlighted in my last post will work. (???)
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  29. #29
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: remove hyperlinks

    Must be the way you have placed the hyperlinks into the cells as it works fine on my Excel XP version.
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  30. #30
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: remove hyperlinks

    Here is the formula in cell F10. It displays as a blue underlined link:

    =HYPERLINK("http://www.yahoo.com")
    Code:
    Sub Macro1()
    MsgBox ActiveSheet.Hyperlinks.Count
    End Sub
    Reports "0" in Excel '97
    Reports "0" in Excel 2003

    Clicking on the link on the sheet also brings up Yahoo in a browser window.

    I've shown you mine ... now you show me yours!
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

  31. #31
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: remove hyperlinks

    Tools Menu...

    Insert Hyperlink.. This counts as a hyperlink and not a formula..

    or quite simply...

    Type www.vbforums.com when on a cell. it changes to underlined text and is included in the hyperlinks count..

    Now type the following into the immediate window and notice that 1 is returned

    ?activesheet.hyperlinks.count

    This was done in excel 2003.
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

  32. #32
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: remove hyperlinks

    Ahhh ... So there are TWO different kinds of Hyperlinks!
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

Posting Permissions

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



Click Here to Expand Forum to Full Width