|
实际上,应该有一个持久性保存最后单号及日期的方法,否则无法实现你的需求,可以用一个文件保存。在工作簿打开时获取,关闭时保存。- Public lastDate As Date
- Public lastID As Long
- Private Sub Workbook_BeforeClose(Cancel As Boolean)
- Dim fileID As Long
- Dim str As String
- fileID = FreeFile()
- Open ThisWorkbook.Path & "\lastDateID.txt" For Output As #fileID
-
- Print #fileID, Format(lastDate, "yyyy-mm-dd")
-
- Print #fileID, lastID & ""
-
- Close #fileID
- End Sub
- Private Sub Workbook_Open()
- Dim fileID As Long
- Dim str As String
- fileID = FreeFile()
- Open ThisWorkbook.Path & "\lastDateID.txt" For Input As #fileID
-
- Line Input #fileID, str
- lastDate = CDate(str)
- Line Input #fileID, str
- lastID = CLng(str)
- Close #fileID
- If Year(lastDate) <> Year(Date) Or Month(lastDate) <> Month(Date) Then
- lastDate = Date
- lastID = -1
-
- End If
- Sub Call送货单号()
- '送货单
- Dim strpo As String
- Application.ScreenUpdating = False '停止刷新
- 'Dim a
- 'a = [K10]
- 'If Day(a) = 1 Then [N2] = 0
- ThisWorkbook.lastID = ThisWorkbook.lastID + 1
- 'Sheets("送货单").[N2].Value = Sheets("送货单").[N2].Value + 1 '在原有编号+1
- 'strpo = Format(Date, "yymmdd") & Format(Sheets("送货单").[N2].Value, "0000") '单号年月日+0000
- strpo = Format(Date, "yymmdd") & Format(ThisWorkbook.lastID, "0000") '单号年月日+0000
- Sheets("送货单").[L8].Value = strpo '单号所在单元格
- Sheets("送货单").[N2].Value = ThisWorkbook.lastID '不需要可删除
- Application.ScreenUpdating = True '刷新
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|