excel 在word中标记单元格结尾标记

uqjltbpv  于 2023-01-27  发布在  其他
关注(0)|答案(1)|浏览(138)

我正在探索在转换为文本文件时使用word来“捕获格式”。
总体目标是捕获自定义文档结构和格式时,转换为文本文件。即生成一个文本文件,说(粗体)如果文本是粗体,或(下划线)如果下划线等。
根据前面的问题,这通常用于生成文本文件,将句子捕获为while(即不引入不必要的换行符),然后可以使用power query读取这些文本文件。
最终,这被证明是有用的,但我已经意识到,一个文档的结构和格式有价值的信息,到目前为止还没有捕获。
我昨天才意识到,使用word来查找和替换格式特征是可行的。在下面的图片中,我使用word来识别文本是否有下划线,并将其替换为之前的文本(HEADER)。对于大多数格式标记(如Tab),可能也可以这样做。

在大多数情况下,动态标记文本文件中的标题,然后我可以使用它在power query中创建一个函数,以迭代各种类似的文档,并开始将文本分隔为相关的部分。
话虽如此,我还是遇到了end of cell marker,如下所示:

最初,我认为用另一个字符(|)查找和替换这样的标记是可行的,然而,似乎不能用上述方法搜索该格式标记。
也就是说,人们似乎有一些希望使用VBA来做类似的事情,以获得Chr(13),这显然是它的价值,并认识到它。
我只想创建一个脚本,用某个字符标记单元格标记的每一端。

bd1hkmkf

bd1hkmkf1#

找到这个答案:https://answers.microsoft.com/en-us/msoffice/forum/all/add-character-before-end-of-cell-marker-in-word/2b7fe2c3-e96e-4d34-a887-b1ddf17d512f

'If you want to add the character to only the cell that contains the cursor, use this (see http://www.gmayor.com/installing_macro.htm if needed):

    

Sub AddToSelectedCell()
    Dim cl As Cell

    If Selection.Information(wdWithInTable) Then
        Set cl = Selection.Cells(1)
        cl.Range.Text = _
            Left(cl.Range.Text, Len(cl.Range.Text) - 2) _
            & "a"  ' <= the character you want to add
    Else
        MsgBox "Put the cursor in the cell and rerun this macro."
    End If
End Sub

'If you want to add the same character to the end of every cell in the table that contains the cursor, use this instead:

Sub AddToEveryCell()
    Dim tbl As Table
    Dim rw As Row
    Dim cl As Cell
    
    If Selection.Information(wdWithInTable) Then
        Set tbl = Selection.Tables(1)
        For Each rw In tbl.Rows
            For Each cl In rw.Cells
                cl.Range.Text = _
                    Left(cl.Range.Text, Len(cl.Range.Text) - 2) _
                    & "a"  ' <= the character you want to add
            Next cl
        Next rw
    Else
        MsgBox "Put the cursor in the table and rerun this macro."
    End If
End Sub

相关问题