VBA列表以贴纸格式存放

时间:2012-11-07 11:35:57

标签: excel vba excel-vba excel-2010

我有一份需要在贴纸上打印的数据列表(想象一下Avery类型)。我无法提出能产生预期结果的代码:

到目前为止我的代码是:

With wsEtiketten
    ' erase old data
    .Cells.Clear
    ' enter new data
    With .Cells(1, 2)
        .Value = "Lettrine"
        .Font.Bold = True
    End With
    .Cells(2, 2).Value = sAuswertungsLettrine
    For i = 0 To MaxRow - 1
        For j = 0 To 4
            r.Copy .Cells(4, 2).Offset(i * 5, j * 5)
            .Cells(4, 2).Offset((i * 5) + 1, (j * 5) + 0) = wsSheet.ListObjects(1).DataBodyRange.Cells(i + 1, 1).Value 'Page
            .Cells(4, 2).Offset((i * 5) + 1, (j * 5) + 1) = wsSheet.ListObjects(1).DataBodyRange.Cells(i + 1, 2).Value 'Ordernr
            .Cells(4, 2).Offset((i * 5) + 1, (j * 5) + 2) = wsSheet.ListObjects(1).DataBodyRange.Cells(i + 1, 8).Value 'Surf
            .Cells(4, 2).Offset((i * 5) + 1, (j * 5) + 3) = wsSheet.ListObjects(1).DataBodyRange.Cells(i + 1, 9).Value 'Indice DB
            .Cells(4, 2).Offset((i * 5) + 3, (j * 5) + 0) = wsSheet.ListObjects(1).DataBodyRange.Cells(i + 1, 3).Value 'Count
            .Cells(4, 2).Offset((i * 5) + 3, (j * 5) + 1) = wsSheet.ListObjects(1).DataBodyRange.Cells(i + 1, 4).Value 'CA Brut
            .Cells(4, 2).Offset((i * 5) + 3, (j * 5) + 3) = wsSheet.ListObjects(1).DataBodyRange.Cells(i + 1, 7).Value 'Marge
        Next j
    Next i
End With

与行相关的信息只是在行中重复。每次字段偏移时我都需要更改。我怎样才能做到这一点?我敢肯定这可能是编程幼儿园的东西,但我没有得到它。

谢谢!

2 个答案:

答案 0 :(得分:2)

也许是一个出乎意料的扭曲的答案。您可以将Excel表与Word结合使用以获得所需的结果。这是标准的Office功能:

http://support.microsoft.com/kb/318117/en

或德语:

http://support.microsoft.com/kb/318117/de

答案 1 :(得分:1)

确定。我设法在Excel中找到答案。一旦我拥有它,很明显。 这是:

With wsEtiketten
    ' Alte Daten werden gelöscht
    .Cells.Clear
    ' Neue Daten werden eingelesen
    With .Cells(1, 2)
        .Value = "Lettrine"
        .Font.Bold = True
    End With
    .Cells(2, 2).Value = sAuswertungsLettrine
    For i = 0 To MaxRow - 1
            r.Copy .Cells(4, 2).Offset(WorksheetFunction.RoundDown(i / 5, 0) * 5, ((i + 5) Mod 5) * 5)
            .Cells(4, 2).Offset((WorksheetFunction.RoundDown(i / 5, 0)) * 5 + 1, ((i + 5) Mod 5) * 5 + 0) = wsSheet.ListObjects(1).DataBodyRange.Cells(i + 1, 1).Value 'Page
            .Cells(4, 2).Offset((WorksheetFunction.RoundDown(i / 5, 0)) * 5 + 1, ((i + 5) Mod 5) * 5 + 1) = wsSheet.ListObjects(1).DataBodyRange.Cells(i + 1, 2).Value 'Bestellnummer
            .Cells(4, 2).Offset((WorksheetFunction.RoundDown(i / 5, 0)) * 5 + 1, ((i + 5) Mod 5) * 5 + 2) = wsSheet.ListObjects(1).DataBodyRange.Cells(i + 1, 8).Value 'Surf
            .Cells(4, 2).Offset((WorksheetFunction.RoundDown(i / 5, 0)) * 5 + 1, ((i + 5) Mod 5) * 5 + 3) = wsSheet.ListObjects(1).DataBodyRange.Cells(i + 1, 9).Value 'Indice DB
            .Cells(4, 2).Offset((WorksheetFunction.RoundDown(i / 5, 0)) * 5 + 3, ((i + 5) Mod 5) * 5 + 0) = wsSheet.ListObjects(1).DataBodyRange.Cells(i + 1, 3).Value 'Anzahl
            .Cells(4, 2).Offset((WorksheetFunction.RoundDown(i / 5, 0)) * 5 + 3, ((i + 5) Mod 5) * 5 + 1) = wsSheet.ListObjects(1).DataBodyRange.Cells(i + 1, 4).Value 'CA Brut
            .Cells(4, 2).Offset((WorksheetFunction.RoundDown(i / 5, 0)) * 5 + 3, ((i + 5) Mod 5) * 5 + 3) = wsSheet.ListObjects(1).DataBodyRange.Cells(i + 1, 7).Value 'Marge
    Next i
End With