Excel:如何仅使用一张纸打印唯一页面

Excel:如何仅使用一张纸打印唯一页面

我正在尝试创建一个模板在 MS Excel 中打印类似的页面,但使用唯一身份在每个打印页面中(例如 ID:001、002 等等),但只能从一张纸上打印。

我正在创建类似日志的东西(即每一页都相同,只有 UID 不同)

有没有办法做到这一点,而不用复制同一张表并手动插入 UID?

如果问题不清楚,我会重新表述。提前谢谢!

答案1

这是我使用的方法的答案: - 创建一个宏来自动更改单元格的值并调用打印机打印页面。代码的重要部分是循环和打印。

创建宏并运行它:

Sub PageNumber()
Application.Dialogs(xlDialogPrinterSetup).Show
For I = 1 To 50
ActiveSheet.Range("G28").Value = "Page " & I & " of 50"
ActiveSheet.Range("G28").Select
With Selection
    HorizontalAlignment = xlRight
    <insert all your cell formatting here>
End With
ActiveWindow.SelectedSheets.Printout Copies:=1, Collate:=True
Next
End Sub

答案2

我有一个宏,可以从数据库表中提取数据,并用该数据反复填充模板表。

数据导入模板

宏会填写模板并将每个模板保存为单独的文件或创建单独的工作表,由您选择。最后一部分可以调整以执行其他操作,这主要是为了演示一种从基于行的数据库填写表单的简单方法。

那里有一个示例文件,供您进行简单测试并开始使用。以下是该宏的主要内容:

Option Explicit

Sub FillOutTemplate()
'Jerry Beaucaire  4/25/2010
'From Sheet1 data fill out template on sheet2 and save
'each sheet as its own file.
Dim LastRw As Long, Rw As Long, Cnt As Long
Dim dSht As Worksheet, tSht As Worksheet
Dim MakeBooks As Boolean, SavePath As String

Application.ScreenUpdating = False  'speed up macro execution
Application.DisplayAlerts = False   'no alerts, default answers used

Set dSht = Sheets("Data")           'sheet with data on it starting in row2
Set tSht = Sheets("Template")       'sheet to copy and fill out

'Option to create separate workbooks
    MakeBooks = MsgBox("Create separate workbooks?" & vbLf & vbLf & _
        "YES = template will be copied to separate workbooks." & vbLf & _
        "NO = template will be copied to sheets within this same workbook", _
            vbYesNo + vbQuestion) = vbYes

If MakeBooks Then   'select a folder for the new workbooks
    MsgBox "Please select a destination for the new workbooks"
    Do
        With Application.FileDialog(msoFileDialogFolderPicker)
            .AllowMultiSelect = False
            .Show
            If .SelectedItems.Count > 0 Then    'a folder was chosen
                SavePath = .SelectedItems(1) & "\"
                Exit Do
            Else                                'a folder was not chosen
                If MsgBox("Do you wish to abort?", _
                    vbYesNo + vbQuestion) = vbYes Then Exit Sub
            End If
        End With
    Loop
End If

'Determine last row of data then loop through the rows one at a time
    LastRw = dSht.Range("A" & Rows.Count).End(xlUp).Row

    For Rw = 2 To LastRw
        tSht.Copy After:=Worksheets(Worksheets.Count)   'copy the template
        With ActiveSheet                                'fill out the form
            'edit these rows to fill out your form, add more as needed
            .Name = dSht.Range("A" & Rw)
            .Range("B3").Value = dSht.Range("A" & Rw).Value
            .Range("C4").Value = dSht.Range("B" & Rw).Value
            .Range("D5:D7").Value = dSht.Range("C" & Rw, "E" & Rw).Value
        End With

        If MakeBooks Then       'if making separate workbooks from filled out form
            ActiveSheet.Move
            ActiveWorkbook.SaveAs SavePath & Range("B3").Value, xlNormal
            ActiveWorkbook.Close False
        End If
        Cnt = Cnt + 1
    Next Rw

    dSht.Activate
    If MakeBooks Then
        MsgBox "Workbooks created: " & Cnt
    Else
        MsgBox "Worksheets created: " & Cnt
    End If

Application.ScreenUpdating = True
End Sub

答案3

我使用了 MS Word 中的邮件合并功能。只需将星期几和日期放在单独的 excel 文件中,然后将我的文档复制到 word 文件中,然后使用信件邮件合并来更改每个文档上的日期和日期。非常简单。

相关内容