【发布时间】:2020-04-19 13:26:47
【问题描述】:
对 VBA 非常缺乏经验,但正在尝试处理一个项目。我有一个包含大量联系信息的 excel 文件。每个条目都包含特定家庭的姓名、电话号码、地址。
我正在使用这些信息创建一个地址簿,这需要一个 Word 文档(是的,还有其他方法可以做到这一点,但这是一个联合项目,这是选择的方法)。
我能够以我想要的方式填充整个通讯录,包括页面和页面格式等。
显然,大部分情况是有序地阅读工作簿,并使用 TypeText 将各种信息放在我想要的位置。
不过,我也想把这个做成pdf,放在我的手机上,把电话号码做成超链接,这样我就可以直接拨号了。我唯一的障碍是维护从 Excel 到 Word 的传输中的超链接。似乎 .TypeText 只携带文本,而不是超链接格式,所以它没有做我需要的。
还有什么我可以做的吗?
我认为有一种复制/粘贴安排可以帮助我,但我缺乏足够的经验来在我的代码中间插入这样的例程。
这是将电话号码转移过来的代码:
对于 y3 = (b + 1) 到 d
'FirstPhone
.TypeText Value(Cells(y3, 7)) & vbTab
'LastName
.BoldRun
If Cells(y3, 20) = "U" Then .Font.Underline = wdUnderlineSingle
.TypeText (Cells(y3, 3))
.Font.Underline = wdUnderlineNone
.BoldRun
'Logic to determine if there needs to be a hard return, and if there are more phones
' Add if there is a spouse, or children, etc
.TypeText (", " & Cells(y3, 4))
If Cells(y3, 5).Value <> "" Then .TypeText (" & " & Cells(y3, 5))
If Cells(y3, 6) <> "" Then .TypeText ("; " & Cells(y3, 6))
Names = Cells(y3, 3) & ", " & Cells(y3, 4) & " & " & Cells(y3, 5) & "; " & Cells(y3, 6)
Address = Cells(y3, 15) & ", " & Cells(y3, 17) & ", " & Cells(y3, 18) & " " & Cells(y3, 19)
If Len(Names) + Len(Address) > 70 Or Cells(y3, 8) <> "" Then .TypeText (Chr(11))
If Cells(y3, 8) = "" And Address = ", , " Then .TypeText (Chr(11))
If Cells(y3, 8) <> "" Then .TypeText (Cells(y3, 8))
If Cells(y3, 15) <> "" Then .TypeText (vbTab & Address)
If Cells(y3, 8) <> "" Or Cells(y3, 15) <> "" Then .TypeText (Chr(11))
If Cells(y3, 9) <> "" Then .TypeText (Cells(y3, 9) & Chr(11))
If Cells(y3, 10) <> "" Then .TypeText (Cells(y3, 10) & Chr(11))
If Cells(y3, 11) <> "" Then .TypeText (Cells(y3, 11) & Chr(11))
Next y3
y3 是行的索引。工作簿中的第 7 列是电话号码所在的位置。本节的其余部分专门用于引入地址等......对于这个问题来说并不是那么必要。
在这段代码之前,我已经创建了 Word Doc,选择了一些格式,并在 Word Doc 中打印了一个节标题。这就是为什么我可以从这里开始,只需将相关单元格的内容键入文本即可。
我想知道的是:如何在此处复制电话号码的超链接,而不是简单地将文本输入 WordDoc?
谢谢。
【问题讨论】:
标签: excel vba hyperlink ms-word