我有一个存储了6条信息的数组,其中之一就是存储条件。有四种不同的储存条件(-80C,RT,2-8,-20C)。我正在遍历数组,然后填充一个Avery标签模板,这是一个表。我可以很好地填充标签模板,但是我想更改存储条件字的字体/颜色。我在隔离细胞中的特定元素方面有困难。
以下是我所拥有的:
'populating cell with array containing information
.Cell(r, c).Range.Text = arrEl(x, 0) & " "& arrEl(x, 1) & " "& arrEl(x, 2)
.Cell(r, c).Range.Text =.Cell(r,c).Range.Text + arrEl(x, 3) + " "+ arrEl(x, 4) + " "+ arrEl(x, 5)
'Changing font and style of each cell
With .Cell(r, c).Range
.Font.Name = "Times New Roman"
.Font.Size = 8
Debug.Print .Paragraphs(2).Range.Words.Last
'I've tried .Words.Count to tell he how many words
'I've tried .Words(1)
End With我正在使用Debug.Print定位和隔离存储条件(即,arrEl(x,5),一旦它在Word中的单元格中)。我遇到两个问题:
有什么建议吗?
发布于 2019-03-21 17:04:32
您说存储条件在“arrEl(x,5)”中
如果是这样的话,您需要更改这一行
.Cell(r, c).Range.Text =.Cell(r,c).Range.Text + arrEl(x, 3) + " "+ arrEl(x, 4) + " "+ arrEl(x, 5)至
.Cell(r, c).Range.Text =.Cell(r,c).Range.Text & arrEl(x, 3) & " "+ arrEl(x, 4) & " "
Set my_range = .cell(r,c).range
my_range.collapse direction:=wdcollapseend
.Cell(r,c).range.text = .Cell(r,c).range.text & arrEl(x, 5)
my_range.end = .Cell(r,c).range.end此时,my_range应该只包含来自arrEl(x,5)的文本,因此您现在可以将所需的字体格式应用到my_range中。
当然,您需要在代码中插入一个Dim my_range作为Word.range。
编辑
为了确保在范围内不包含任何单元格或段落标记,我们可以使用.MoveEndUntil方法。在提供的范围示例中,表示流行结束的一组字符是"CT8“。所以我们可以
my_range.MoveEndUntil cset:="CT8", count:=wdbackwards发布于 2019-03-21 15:50:37
使用Word VBA,下面标识表单元格中的文本:
ActiveDocument.Tables(1).Cell(1,1).Range.Text您可以在以下情况下更改单元格中单词的字体特征:
ActiveDocument.Tables(1).Cell(1,1).Range.Words(2).Font.ColorIndex = 3或对整个文本使用以下内容:
ActiveDocument.Tables(1).Cell(1,1).Range.Font.ColorIndex = 3如果从Excel编写此代码,则检查是否引用了Word及其表。
如果需要,可以修改单元格中的文本。
ActiveDocument.Tables(1).Cell(1,1).Range.Text = "foo bar"你可以得到最后一句话
ActiveDocument.Tables(1).Cell(1,1).Range.Words( _
ActiveDocument.Tables(1).Cell(1,1).Range.Words.Count - 1)虽然这可以通过中间引用进行简化。Count - 1忽略了结束单元格标记(或它称为什么)。
https://stackoverflow.com/questions/55284170
复制相似问题