奇怪的字数在Word表上

时间:2017-10-31 12:16:57

标签: vba ms-word

我正在创建一个VBA脚本,当我想计算两个单词之间的行数时,发生了一件奇怪的事情。

当两个单词之间存在一个表格时,进入表格的行数是错误的,即第一行在行23中,第二行在行17中,第三行在行23中,第四行在行18中。

enter image description here enter image description here enter image description here enter image description here

我使用此代码:

Sub delete() 'Eliminar los apartados que no aplican

    Dim intCurrentLine, toLine, aux As String

    With ActiveDocument.Content.Find
        .Text = "[word1]"
        Do While .Execute(Forward:=True, Format:=True) = True
            Selection.Find.Execute FindText:=("[word1]")
            intCurrentLine = Selection.Range.Information(wdFirstCharacterLineNumber)
            Selection.MoveLeft Unit:=wdWord, Count:=1
            Selection.Find.Execute FindText:=("[word2]")
            toLine = Selection.Range.Information(wdFirstCharacterLineNumber)
            Selection.HomeKey Unit:=wdStory
            Selection.Find.Execute FindText:=("[word1]")
            Selection.MoveLeft Unit:=wdWord, Count:=1

            'Contar paginas, si la pagina si hay mas de una pagina, se recorre la pagina para contar y sumar las lineas.

            If toLine > intCurrentLine Then
                Selection.MoveDown Unit:=wdLine, Count:=toLine - intCurrentLine + 1, Extend:=wdExtend
            Else
                Selection.GoToNext (wdGoToPage)
                Selection.MoveEnd wdCharacter, -1
                aux = Selection.Range.Information(wdFirstCharacter)
                Selection.HomeKey Unit:=wdStory
                Selection.Find.Execute FindText:=("[word1]")
                Selection.MoveLeft Unit:=wdWord, Count:=1
                Selection.MoveDown Unit:=wdLine, Count:=aux - intCurrentLine + toLine + 1, Extend:=wdExtend
            End If
            Selection.delete
            intCurrentLine = 0
            fromLine = 0
        Loop
    End With
End Sub

有什么问题?我该怎么做才能解决它?

1 个答案:

答案 0 :(得分:1)

我不完全确定您的要求,但修改了您的代码 - 请试试这个并让我知道它是否适合您:

add_action( 'woocommerce_admin_order_data_after_shipping_address', 'cwn_add_pickup_to_order_item_meta', 10, 1 );
function cwn_add_pickup_to_order_item_meta( $order ){
    echo '<div>';
    foreach($order->get_shipping_methods() as $shipping_method ){
        echo '<p><strong>Shipping Method ID:</strong> '. $shipping_method->get_method_id().'<br>
        <strong>Shipping Method name:</strong> '. $shipping_method->get_name().'<br>
        <strong>Shipping Method title:</strong> '. $shipping_method->get_method_title().'<br>
        <strong>Shipping Method Total:</strong> '. $shipping_method->get_total().'<br>
        <strong>Shipping Method Total tax:</strong> '. $shipping_method->get_total_tax().'</p><br>';
    }
    echo '</div>';
}

注意:

我添加了一个单词1&amp; 2在同一页面上,但真的不确定是否需要。