在Excel中将超链接转换为HTML代码 [英] Convert Hyperlinks to HTML code in Excel

查看:247
本文介绍了在Excel中将超链接转换为HTML代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Excel文件中有一列超链接,我想将它们转换为各自的HTML代码:

I have a column of hyperlinks in an Excel file and I want to convert them to their respective HTML code:

<a href="http://www.example.com">Link Name</a>

我找到了仅提取链接(作为文本)的方法,但是我需要整个HTML代码作为文本来替换单元格中的超链接.

I found ways to extract the link only (as text), but I need the whole HTML code as text to replace the hyperlink in the cell.

我已经搜索了,但是我猜没有人需要这个答案.有人可以帮忙吗?

I've searched and searched but no one needed this answer, I guess. Can someone help?

推荐答案

实际上,这是从

It is actually a fairly straightforward method to yank the .Address and optional .SubAddress from the Hyperlinks collection object. The .TextToDisplay property is simply the value or text of the cell.

Sub html_anchors()
    Dim a As Range, u As String, l As String
    Dim sANCHOR As String: sANCHOR = "<a href=""%U%"">%L%</a>"

    For Each a In Selection
        With a
            If CBool(.Hyperlinks.Count) Then
                l = .Text
                u = .Hyperlinks(1).Address
                If Right(u, 1) = Chr(47) Then u = Left(u, Len(u) - 1)
                .Hyperlinks(1).Delete
                .Value = Replace(Replace(sANCHOR, "%U%", u), "%L%", l)
            End If
        End With
    Next a
End Sub

选择要处理的所有单元并运行例程.如果您选择的任何单元格都不包含超链接,则它将被忽略.

Select all of the cells you want to process and run the routine. If any cell in your selection does not contain a hyperlink, it will be ignored.

这篇关于在Excel中将超链接转换为HTML代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆