当文本存储在字符串中时,删除了上标的格式

发布于 2025-02-01 03:39:33 字数 301 浏览 2 评论 0 原文

Dim ST As String
ST = ActiveDocument.Paragraphs(1).Range.Text

在我的文档中,段(1)实际上是 2 + 3 2 。但是,使用 debug.print st ,输出为 2 + 32 。有什么办法可以存储数据而不损害上标和下标?

其背后的目的是将5行存储在 st(1至5)中,然后洗牌5行的顺序。

Dim ST As String
ST = ActiveDocument.Paragraphs(1).Range.Text

In my document, Paragraphs(1) is actually 2 + 32. However, with Debug.Print ST, the output is 2 + 32. Is there any way to store the data without compromising the superscript and subscript formatting?

The objective behind this is to store 5 lines in ST(1 to 5) and then shuffle the order of the 5 lines.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌无敌 2025-02-08 03:39:33

1-尚不清楚您要如何捕获段落,因此我假设您将选择这些段落,请根据您的要求进行修改

2-还不清楚什么 shuffle 意思是这样,我会假设您希望它被逆转,您需要以自己的逻辑来掌握有关如何进行 shuffle 段落的逻辑:

属性可用于用格式化的文本替换范围

Private Sub ShuffleSelectedParagraphs()
        
    ActiveDocument.Content.InsertParagraphAfter
    
    Dim i As Long
    For i = Selection.Paragraphs.Count To 1 Step -1
        ActiveDocument.Content.Paragraphs.Last.Range.FormattedText = Selection.Paragraphs(i).Range.FormattedText
    Next
End Sub

com/en-us/office/vba/api/word.range.range.formattedText“ rel =” nofollow noreferrer“ > 需要首先选择段落,然后运行 sub ,它将在文档末尾复制所选段落,但按反向顺序重复。

1 - It is not clear how do you want to capture the paragraphs so I'm assuming that you will have those paragraphs selected, modify it based on your requirement

2 - It is also not clear on what shuffle means so I will assume that you want it to be reversed, you will need to come out with your own logic on how to shuffle the paragraphs:

FormattedText property can be used to replace a range with formatted text so this should work for you:

Private Sub ShuffleSelectedParagraphs()
        
    ActiveDocument.Content.InsertParagraphAfter
    
    Dim i As Long
    For i = Selection.Paragraphs.Count To 1 Step -1
        ActiveDocument.Content.Paragraphs.Last.Range.FormattedText = Selection.Paragraphs(i).Range.FormattedText
    Next
End Sub

You will need to select the paragraphs first then run the Sub, it will duplicate the selected paragraphs at the end of the document but in the reverse order.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文