所以我在Word上创建一个标签制作宏,将一个标签复制并粘贴到指定数量的标签中。问题是表格已设置为每个标签之间有1个空白列,每行标签之间有1个空白行。每行有7个标签,每列17个。创建标签的位置高度为0.5“,宽度为0.94”。中间的列具有0.13“宽度,并且其间的行具有0.13”高度。所以我根据单元格尺寸编写了代码。但是,它不起作用。它没有给出错误,但它粘贴到每个单元格而不是跳过那些太小的单元格。附上标签模板的图片。我不确定这是否是最佳方式,所以任何见解都会受到赞赏!
Sub labels()
Dim tbl As Table
Set tbl = ActiveDocument.Tables(1)
For i = 1 To labels2.TextBox3.Value
If tbl.Rows.Height < 0.5 And tbl.Columns.Width < 0.9 Then
Selection.MoveRight unit:=wdCharacter, Count:=2
Else
Selection.Paste
Selection.MoveRight unit:=wdCharacter, Count:=2
End If
Next i
End Sub
答案 0 :(得分:0)
如果你知道你总是需要跳过每个标签和每行之间的一行,你可以这样做:
Sub labels()
Dim numLabels As Long, i As Long
Dim tbl As Table, rw As Long, c As Long
Set tbl = ActiveDocument.Tables(1)
numLabels = 10
i = 0
For rw = 1 To tbl.Rows.Count Step 2
For c = 1 To tbl.Columns.Count Step 2
tbl.Cell(rw, c).Range.Paste
i = i + 1
If i = numLabels Then GoTo done
Next c
Next rw
done:
MsgBox "Labels Created"
End Sub