从Word中以表格形式复制文本并恢复格式 [英] Copy Text from Table in Word and Retaing Formatting

查看:163
本文介绍了从Word中以表格形式复制文本并恢复格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将单元格从表复制到另一个单元格时遇到问题.我在这里谈论两个单词文档.我可以复制文本,但项目符号不见了,其中有些格式已经格式化.

I have a problem copying a cell from a table to another cell. I'm talking about two word documents here. I can copy the text but the bullets are gone and some of the formatting.

我尝试了.Formattedtext,但仍然无法做到.

I tried .Formattedtext but still can't do it.

Dim test As Word.Cell

'An error occurs something like "Object variable or With block variable not set"
test.Range.FormattedText = CTPDoc.Tables(2).Rows(testCount).Cells(3).Range.FormattedText

推荐答案

这里是一个示例.

假设我们在一个word文档中有两个表.参见下面的截图

Let's say we have two tables in a word document. See screenshot below

假设我们要将数据从Table 1Cell 1粘贴到Table 2Cell 1,然后尝试执行此操作

Let's say we want to paste the data from Cell 1 of Table 1 to Cell 1 of Table 2 then try this

Sub Sample()
    Dim tbl1 As Table, tbl2 As Table

    Set tbl1 = ActiveDocument.Tables(1)
    Set tbl2 = ActiveDocument.Tables(2)

    tbl1.Cell(1, 1).Range.Copy
    tbl2.Cell(1, 1).Range.PasteAndFormat (wdFormatOriginalFormatting)
End Sub

这就是宏的作用

希望这会有所帮助:)

这篇关于从Word中以表格形式复制文本并恢复格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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