Dim cj2 As WinForm.DateTimePicker = e.Form.Controls("DateTimePicker2")
Dim y,m,d As Integer
Dim dt2 As Date
dt2 = vars("cc")
Dim dt1 As Date = #1/01/0001#
DateYMD(dt1,dt2, y, m, d)
y=y+1
m=m+1
d=d+1
Dim f0 As String = "E:\快盘\fyyw\fydb" & y & Format(m,"00") & ".xls" '快盘本月单表
Dim f1 As String ="E:\快盘\fyyw\fydb" & y & Format(m-1,"00") & ".xls" '快盘上月单表
Dim f2 As String ="E:\快盘\fyyw\fydb" & y-1 & Format(m,"00") & ".xls" '快盘上年单表
Dim f3 As String = "E:\快盘\fyyw\fyhz" & y & Format(m,"00") & ".xls" '快盘本月集团汇总
Dim f4 As String ="E:\快盘\fyyw\fydb" & y-1 & "12.xls" '快盘上年单表
Dim f5 As String ="E:\财务数据汇总\模板\汇总单表附.xls"
If cj2.text = Nothing Then
messagebox.show("请输入日期!")
Else If not FileSys.FileExists(f3) Then
messagebox.show("快盘不存在fyhz" & y & "0" & m)
Else If FileSys.FileExists(f0) Then
messagebox.show("快盘已存在fydb" & y & "0" & m)
Else
Dim Book2 As New XLS.Book(f2)
Dim Book3 As New XLS.Book(f3)
Dim Book4 As New XLS.Book(f4)
Dim Book5 As New XLS.Book(f5)
Dim Sheet3 As XLS.Sheet = Book2.Sheets("费用表") '上年同期
Dim Sheet4 As XLS.Sheet = Book3.Sheets("资产负债表") '本月集团汇总
Dim Sheet5 As XLS.Sheet = Book3.Sheets("利润及分配表")
Dim Sheet6 As XLS.Sheet = Book3.Sheets("费用表")
Dim Sheet7 As XLS.Sheet = Book4.Sheets("资产负债表") '上年期未余额
Dim Sheet8 As XLS.Sheet = Book5.Sheets("资产负债表") '模板单表
Dim Sheet9 As XLS.Sheet = Book5.Sheets("利润及分配表")
Dim Sheet10 As XLS.Sheet = Book5.Sheets("费用表")
Dim Sheet11 As XLS.Sheet = Book5.Sheets("分单位")
'资产负债表
If m = 1 Then '资产表年初数
For n As Integer = 5 To 54
If Sheet8(n,3).Formula = "" Then
Sheet8(n,3).Value = Sheet7(n,3).Value
End If
If Sheet8(n,7).Formula = "" Then
Sheet8(n,7).Value = Sheet7(n,7).Value
End If
Next
book5.save(f5)
End If
For n As Integer = 5 To 54 '资产表年未数
If Sheet8(n,4).Formula = "" Then
Sheet8(n,4).Value = Sheet4(4,n-3).Value
End If
If Sheet8(n,8).Formula = "" Then
Sheet8(n,8).Value = Sheet4(4,n+47).Value
End If
Next
'利润表
For n As Integer = 6 To 34
If Sheet9(n,4).Formula = "" Then
Sheet9(n,4).Value = Sheet5(4,n-4).Value '利润表本年数
End If
If Sheet9(n,8).Formula = "" Then
Sheet9(n,8).Value = Sheet5(4,n+26).Value
End If
If m = 1 Then
If Sheet9(n,3).Formula = "" Then
Sheet9(n,3).Value = Sheet9(n,4).Value '利润表本月数
End If
If Sheet9(n,7).Formula = "" Then
Sheet9(n,7).Value = Sheet9(n,8).Value
End If
Else
Dim Book1 As New XLS.Book(f1)
Dim Sheet1 As XLS.Sheet = Book1.Sheets("利润及分配表") '上月单表
If Sheet9(n,3).Formula = "" Then
Sheet9(n,3).Value = val(Sheet9(n,4).Value) - val(Sheet1(n,4).Value) '利润表本月数
End If
If Sheet9(n,7).Formula = "" Then
Sheet9(n,7).Value = val(Sheet9(n,8).Value) - val(Sheet1(n,8).Value)
End If
Sheet9(12,7).Value = Sheet1(33,8).Value
End If
Next
'费用表
'管理费用和经营费用
For n As Integer = 4 To 31
If Sheet10(n,4).Formula = "" Then
Sheet10(n,4).Value = Sheet6(2,n-2).Value '本年累计数
End If
If m = 1 And Sheet10(n,3).Formula = "" Then
Sheet10(n,3).Value = Sheet10(n,4).Value '本月数
Else If Sheet10(n,3).Formula = "" Then
Dim Book1 As New XLS.Book(f1)
Dim Sheet2 As XLS.Sheet = Book1.Sheets("费用表")
Sheet10(n,3).Value = val(Sheet10(n,4).Value) - val(Sheet2(n,4).Value) '本月数
End If
Sheet10(n,5).Value = Sheet3(n,4).Value '去年同期数
Next
'财务费用
Sheet10(33,4).Value = Sheet6(2,30).Value '本年累计数
If m = 1 Then
Sheet10(33,3).Value = Sheet10(33,4).Value '本月数
Else
Dim Book1 As New XLS.Book(f1)
Dim Sheet2 As XLS.Sheet = Book1.Sheets("费用表")
Sheet10(33,3).Value = val(Sheet10(33,4).Value) - val(Sheet2(32,4).Value) '本月数
End If
Sheet10(33,5).Value = Sheet3(33,4).Value '去年同期数
'分单位表
For n As Integer = 5 To 34
Sheet11(n,2).Value = Sheet5(n,2).Value '销售收入
Sheet11(n,3).Value = Sheet5(n,33).Value '利润总额
Sheet11(n,4).Value = Sheet4(n,77).Value '资本金
Sheet11(n,5).Value = Sheet4(n,9).Value
Sheet11(n,6).Value = Sheet4(n,91).Value
Sheet11(n-1,7).Value = val(Sheet6(n-3,35).Value) / val(Sheet5(n-1,2).Value)
Sheet11(n-1,7).Value = Round2( val(Sheet11(n-1,7).Value) ,2)
Next
book5.save(f0)
Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.open(f0)
For Each Ws As MSExcel.WorkSheet In Wb.WorkSheets
ws.cells(2,2) = cj2.text
ws.UsedRange.Formula = ws.UsedRange.Formula
If ws.name <> "分单位" Then
ws.Activate
app.ActiveWindow.DisplayZeros = False
End If
With Ws.PageSetup '设置打印区域
If ws.name = "资产负债表" Then
.PrintArea = "A1:I57" '打印工作表的指定区域
Else If ws.name = "利润及分配表" Then
.PrintArea = "A1:I38" '打印工作表的指定区域
Else If ws.name = "费用表" Then
.PrintArea = "A1:G40" '打印工作表的指定区域
Else If ws.name = "分单位表" Then
.PrintArea = "A1:H36" '打印工作表的指定区域
End If
End With
Next
wb.save
wb.close
App.Quit
Dim Proc As New Process
Proc.File = (f0)
Proc.Start()
End If