簡體   English   中英

在 word 中標記單元格結束標記

[英]Tag end-of-cell marker in word

我正在探索在轉換為文本文件時使用 word 來“捕獲格式”。

總體目標是在轉換為文本文件時捕獲自定義文檔結構和格式。 即生成一個文本文件,如果文本是粗體,則顯示 (BOLD),如果是下划線,則顯示 (UNDERLINED) 等。

根據前面的問題,這通常可以生成文本文件,暫時捕獲句子(即不引入不需要的換行符),然后可以使用 power query 讀取這些文本文件。

最終這被證明是有用的,但我已經意識到文檔的結構和格式具有迄今為止尚未捕獲的有價值的信息。

我昨天才意識到,實際上可以使用 word 來查找和替換格式功能。 在下圖中,我使用 word 來識別文本是否帶有下划線並將其替換為之前的文本 (HEADER)。 可以對大多數格式標記(例如 Tab)執行相同的操作。

在此處輸入圖像描述

在大多數情況下,我可以在文本文件中動態標記標題,然后我可以使用它來創建一個 function 強大的查詢來迭代各種類似的文檔,並開始將文本分成相關的部分。

這就是說我遇到了end of cell marker如下所示:

在此處輸入圖像描述

最初,我認為找到並用另一個字符( | )替換這樣的標記是可行的,但是,似乎無法通過上述方式搜索該格式標記。

話雖這么說,人們似乎有希望使用 VBA 來做類似的事情來獲得Chr(13) ,這顯然是它的價值並認識到它。

我只想創建一個腳本來用一些字符標記單元格標記的每一端。

找到了這個答案: 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM