如何使用VBA修剪MS Word中的表格单元格值 [英] How to trim table cell values in MS Word with VBA

查看:314
本文介绍了如何使用VBA修剪MS Word中的表格单元格值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Word文件中有一个表。
下面的这个vba程序将遍历所有表格单元格

I have a table in a Word file. This vba program below will iterate through all the table cells

Dim strCellText As String
Dim uResp As String
Dim Row As Integer
Dim Col As Integer

Dim itable As Table


For Each itable In ThisDocument.Tables

    uResp = ""

    For Row = 1 To itable.Rows.Count

        For Col = 1 To itable.Columns.Count

            strCellText = itable.Cell(Row, Col).Range.Text
            uResp = uResp & Trim(strCellText)                

        Next

    Next

    MsgBox uResp
Next

在行 uResp = uResp&修剪(strCellText) VBA为每个单元格附加一个换行符和一个点。所以 MsgBox uResp 将显示一个列消息框。我怎么能在显示消息框时删除换行符和点。

In the line uResp = uResp & Trim(strCellText) VBA appends a newline and a dot to each cell.So MsgBox uResp will display a 'column' message box.How can I remove the newline and dot while displaying the message box.

推荐答案

Word使用两个字符作为单元格分隔符,因此请使用

Word uses two characters as the cell delimiter, so use

uResp = uResp & Trim(left(strCellText,len(StrCellText)-2))                

在这种情况下,你将拥有单元格值之间没有分隔符,因此您可能希望连接空格。

In this case, you will have no separator between the cell values, so you might want to concatenate a space.

这篇关于如何使用VBA修剪MS Word中的表格单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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