如何使在其他文字处理器中创建的文件的超链接在 MS Word 中正确显示?

如何使在其他文字处理器中创建的文件的超链接在 MS Word 中正确显示?

在我的工作中,我经常会收到用各种文字处理器创建的文章,我用 Word 2013 打开和编辑这些文章。但是,从兼容性方面来说,它们当然不能很好地协同工作。

虽然不需要进行繁重的格式化,但是我在查看这些文章中的超链接时一直遇到严重的、持续性的问题。

  1. 一个人在 Pages (Mac) 中写作并保存为 .docx。她的文件中的超链接始终带有下划线,但从不带有蓝色下划线,而 Word 中则带有蓝色下划线。我还注意到,如果我要添加指向她创建的文件的链接,它会显示为黑色下划线文本,而不是像我的其他文件那样带有蓝色下划线。

  2. 另一个人以 .rtf 格式发送文件 - 不知道是什么程序,但用的是 Mac。他的文件中的超链接不是格式与其余文本完全不同。只有当您将鼠标悬停在 Word 上时,您才能看到那里有一个链接。在我的 Word 2013 上查看时,超链接和普通文本是相同的。有趣的是,在 Gmail 预览中,这些文件中的链接显示正常(蓝色,带下划线),所以我一直将此用作解决方法。该人曾尝试将其另存为 .docx,但超链接在转换后完全不存在 - 当您将鼠标悬停在它们原来所在的位置时,它们甚至不存在。

有没有一种方法可以让我(而不是这两个)在收到后自动将这些文件更改为超链接正常显示、具有不同颜色和下划线的文件?

情况 1 还可以忍受,但是情况 2 已经痛苦了一段时间。

案例#2 的示例文件(仅包含一个超链接):http://s000.tinyupload.com/index.php?file_id=45065577867642123191

答案1

我研究了示例文件,我想我已经理解了问题的根源:RTF 格式有超链接字段,但没有超链接样式。只有更先进的文档格式才具有这种样式:DOC、DOCX 和 DOCM。

RTF 文档中的超链接字段定义正确,但使用的是 Normal 样式,而不是 Hyperlink 样式。遗憾的是,Word 无法自动更正此问题。

我用来更正示例文件的解决方案是:

  1. 将 RTF 文件保存为 DOCM,这样它将具有超链接样式
    (DOCM 与 DOCX 完全相同,只是允许使用宏)
  2. 运行 VBA 宏,将所有超链接字段的样式设置为超链接

我使用的 VBA 宏如下:

Sub hyper()
For Each oHyperlink In ActiveDocument.Hyperlinks
    oHyperlink.Range.Style = ActiveDocument.Styles("Hyperlink")
Next oHyperlink
ActiveDocument.Range.Fields.Update
End Sub

此解决方案的优点是它将真实的超链接样式分配给所有超链接字段。这比仅进行字体颜色和下划线等外观更改要好。

答案2

如果所有超链接实际上都是超链接(而不仅仅是文本),那么

别再烦恼我的朋友

10 个简单的步骤等着您。

尝试这个:

  1. 按下Alt+F9您想要查看更改的文档(这将转换并显示所有超链接,无需担心)。
  2. 按下Ctrl+H打开Find and Replace
  3. ^d hyperlink在框中输入Find
  4. 移动光标并选择Replace with框,但不要输入任何内容。
  5. 单击MoreReplace with字段下方的按钮。
  6. 单击Format刚刚显示的其他选项下方的按钮。
  7. 点击Style
  8. Hyperlink从列表中选择(按下H键盘上的键可以更轻松地找到它)并单击OK
  9. 点击Replace All,瞧!全部完成了。
  10. 关闭Find and Replace窗口并按Alt+F9

提示:如果您不想每次都为每个文档执行此操作,您可以创建一个宏函数并将其放在功能区上。从那时起,只需单击鼠标即可。

希望能帮助到你。

答案3

对于评论来说太大了(应该是因为它没有经过充分测试并且可能无法满足您的要求)。

如果自动套用格式做得不够(正如我们在评论中的讨论),我认为你需要对每个超链接做相当多的事情,即

  • 确保它已被 Word 识别为超链接(在这种情况下,如果您使用 Alt-F9,您应该能够看到 { HYPERLINK } 字段代码)
  • 将超链接字符样式应用于 HYPERLINK 域的结果
  • 将字符格式重新应用于 HYPERLINK 字段结果,以修复强加超链接样式可能造成的损害

如果导入的文本包含大量超链接,则执行所有这些操作可能会非常繁琐,因此下面的 VBA 旨在修复当前活动的 Word 文档正文中的超链接。

它只会检测 Word 认为是超链接的内容(不一定是您所期望的所有内容)。

如果可能的话,我建议你首先将任何导入的文本作为单独的文档打开,然后运行此代码。这应该可以最大限度地减少不良副作用。

超链接字符样式的问题在于,它应用“默认段落字体”,而该字体可能不具有与现有文本相同的属性(例如大小等)。即使您修改样式以使用“基本属性”,也可能会更改文本大小等。因此,我在这里所做的是查看超链接“显示文本”中第一个字符的属性,并在应用超链接样式后将其重新应用于整个显示文本。

但是如果您将自己的段落样式应用于导入的文本,则使用超链接样式的文本很可能会按照您的要求执行操作,因此您可能能够删除那部分 VBA。

如果您需要在文档中的其他“故事”中查找超链接,例如文本框、页眉/页脚等,那么您肯定需要更多。

Private Type AutoFormatOptions
  bAutoFormatApplyBulletedLists As Boolean
  bAutoFormatApplyFirstIndents As Boolean
  bAutoFormatApplyHeadings As Boolean
  bAutoFormatApplyLists As Boolean
  bAutoFormatApplyOtherParas As Boolean
  bAutoFormatDeleteAutoSpaces As Boolean
  bAutoFormatMatchParentheses As Boolean
  bAutoFormatPlainTextWordMail As Boolean
  bAutoFormatPreserveStyles As Boolean
  bAutoFormatReplaceFarEastDashes As Boolean
  bAutoFormatReplaceFractions As Boolean
  bAutoFormatReplaceHyperlinks As Boolean
  bAutoFormatReplaceOrdinals As Boolean
  bAutoFormatReplacePlainTextEmphasis As Boolean
  bAutoFormatReplaceQuotes As Boolean
  bAutoFormatReplaceSymbols As Boolean
End Type
Sub fixUpHyperlinks()

Dim afo As AutoFormatOptions

Dim f As Word.Font

Dim h As Word.Hyperlink
' Save existing autoformat options

With Application.Options
  afo.bAutoFormatApplyBulletedLists = .AutoFormatApplyBulletedLists
  afo.bAutoFormatApplyFirstIndents = .AutoFormatApplyFirstIndents
  afo.bAutoFormatApplyHeadings = .AutoFormatApplyHeadings
  afo.bAutoFormatApplyLists = .AutoFormatApplyLists
  afo.bAutoFormatApplyOtherParas = .AutoFormatApplyOtherParas
  afo.bAutoFormatDeleteAutoSpaces = .AutoFormatDeleteAutoSpaces
  afo.bAutoFormatMatchParentheses = .AutoFormatMatchParentheses
  afo.bAutoFormatPlainTextWordMail = .AutoFormatPlainTextWordMail
  afo.bAutoFormatPreserveStyles = .AutoFormatPreserveStyles
  afo.bAutoFormatReplaceFarEastDashes = .AutoFormatReplaceFarEastDashes
  afo.bAutoFormatReplaceFractions = .AutoFormatReplaceFractions
  afo.bAutoFormatReplaceHyperlinks = .AutoFormatReplaceHyperlinks
  afo.bAutoFormatReplaceOrdinals = .AutoFormatReplaceOrdinals
  afo.bAutoFormatReplacePlainTextEmphasis = .AutoFormatReplacePlainTextEmphasis
  afo.bAutoFormatReplaceQuotes = .AutoFormatReplaceQuotes
  afo.bAutoFormatReplaceSymbols = .AutoFormatReplaceSymbols
End With
On Error GoTo cleanup

' set everything the way we want

With Application.Options
  ' all false
  .AutoFormatApplyBulletedLists = False
  .AutoFormatApplyFirstIndents = False
  .AutoFormatApplyHeadings = False
  .AutoFormatApplyLists = False
  .AutoFormatApplyOtherParas = False
  .AutoFormatDeleteAutoSpaces = False
  .AutoFormatMatchParentheses = False
  .AutoFormatPlainTextWordMail = False
  .AutoFormatPreserveStyles = False
  .AutoFormatReplaceFarEastDashes = False
  .AutoFormatReplaceFractions = False
  ' except this one
  .AutoFormatReplaceHyperlinks = True
  .AutoFormatReplaceOrdinals = False
  .AutoFormatReplacePlainTextEmphasis = False
  .AutoFormatReplaceQuotes = False
  .AutoFormatReplaceSymbols = False
End With

With ActiveDocument

  ' Apply the selected formats
  .Kind = wdDocumentNotSpecified
  .Content.AutoFormat

  ' Now apply the Hyperlink style to all Hyperlink field result ranges

  For Each h In .Hyperlinks
    With .Range.Fields(1).Result
      If .Characters.Count >= 1 Then
        ' Remove the following line if the Hyperlink style works for you
        Set f = .Characters(1).Font.Duplicate
        ' Apply the Hyperlink style
        .Style = ActiveDocument.Styles(wdStyleHyperlink).NameLocal
        ' Remove the following 2 lines if the Hyperlink style works for you
        Set .Font = f
        set f = Nothing
      End If
    End With
  Next

End With

cleanup:
' restore the original settings

With Application.Options
  .AutoFormatApplyBulletedLists = afo.bAutoFormatApplyBulletedLists
  .AutoFormatApplyFirstIndents = afo.bAutoFormatApplyFirstIndents
  .AutoFormatApplyHeadings = afo.bAutoFormatApplyHeadings
  .AutoFormatApplyLists = afo.bAutoFormatApplyLists
  .AutoFormatApplyOtherParas = afo.bAutoFormatApplyOtherParas
  .AutoFormatDeleteAutoSpaces = afo.bAutoFormatDeleteAutoSpaces
  .AutoFormatMatchParentheses = afo.bAutoFormatMatchParentheses
  .AutoFormatPlainTextWordMail = afo.bAutoFormatPlainTextWordMail
  .AutoFormatPreserveStyles = afo.bAutoFormatPreserveStyles
  .AutoFormatReplaceFarEastDashes = afo.bAutoFormatReplaceFarEastDashes
  .AutoFormatReplaceFractions = afo.bAutoFormatReplaceFractions
  .AutoFormatReplaceHyperlinks = afo.bAutoFormatReplaceHyperlinks
  .AutoFormatReplaceOrdinals = afo.bAutoFormatReplaceOrdinals
  .AutoFormatReplacePlainTextEmphasis = afo.bAutoFormatReplacePlainTextEmphasis
  .AutoFormatReplaceQuotes = afo.bAutoFormatReplaceQuotes
  .AutoFormatReplaceSymbols = afo.bAutoFormatReplaceSymbols
End With

'    Application.Options.AutoFormatApplyBulletedLists
'    Selection.Document.Kind = wdDocumentNotSpecified
'    Selection.Range.AutoFormat
End Sub

相关内容