|
本帖最后由 aslxt 于 2013-5-22 14:32 编辑
分不同的sheet,在你的代码上进行最少的变动,并在变动的地方加以说明了,方便理解:
Private Sub 评估表_Click()
Dim xlApp As New Excel.Application
Dim xlBook As Excel.Workbook
Dim I As Long
xlApp.Application.Visible = True
Set xlBook = xlApp.Workbooks.Open(CurrentProject.Path + "\制造可行性评估表.xls") '变动:原有xlt文件不知如何增加工作表
xlBook.Application.Sheets(1).Select
For I = 1 To Me.报价子窗体.Form.RecordsetClone.RecordCount '变动:根据记录数量在工作簿中添加相应的工作表
Worksheets("Sheet1").Copy After:=Worksheets("Sheet1")'复制模板到新工作表中粘贴
ext I
For I = 1 To Me.报价子窗体.Form.RecordsetClone.RecordCount
Me.报价子窗体.Form.SelTop = I
xlBook.Worksheets("Sheet1 (" & I + 1 & ")").Activate '变动:根据记录激活不同的工作表,便于输出数据
'xlBook.Application.Cells(1, 1).Value = [Forms]![frmSysMain]![txtCurrentUser]
xlBook.Application.Cells(I + 1, 3).Value = Me.报价子窗体.Controls("编号").Value
xlBook.Application.Cells(I + 3, 6).Value = Me.报价子窗体.Controls("产品类别").Value
xlBook.Application.Cells(I + 4, 6).Value = Me.报价子窗体.Controls("技术编号").Value
xlBook.Application.Cells(I + 7, 8).Value = Me.报价子窗体.Controls("客户询价单编码").Value
xlBook.Application.Cells(I + 4, 8).Value = Me.报价子窗体.Controls("客户").Value
xlBook.Application.Cells(I + 5, 6).Value = Me.报价子窗体.Controls("报价图号").Value
xlBook.Application.Cells(I + 5, 8).Value = Me.报价子窗体.Controls("接受时间").Value
xlBook.Application.Cells(I + 5, 10).Value = Me.报价子窗体.Controls("要求时间").Value
xlBook.Application.Cells(I + 5, 12).Value = Me.报价子窗体.Controls("邮件").Value
xlBook.Application.Cells(I + 6, 6).Value = Me.报价子窗体.Controls("品名").Value
xlBook.Application.Cells(I + 6, 8).Value = Me.报价子窗体.Controls("预示量").Value
xlBook.Application.Cells(I + 6, 10).Value = Me.报价子窗体.Controls("客户担当").Value
xlBook.Application.Cells(I + 6, 12).Value = Me.报价子窗体.Controls("电话").Value
xlBook.Application.Cells(I + 8, 7).Value = "询价目的:" & Me.报价子窗体.Controls("新品否").Value & " / 目标价:" & Me.报价子窗体.Controls("目标价格").Value
xlBook.Application.Cells(I + 9, 7).Value = Me.报价子窗体.Controls("预示量").Value
xlBook.Application.Cells(I + 10, 7).Value = Me.报价子窗体.Controls("其他公司").Value
xlBook.Application.Cells(I + 11, 7).Value = "机型:" & Me.报价子窗体.Controls("机型").Value & " / 用途:" & Me.报价子窗体.Controls("用途").Value
xlBook.Application.Cells(I + 12, 7).Value = Me.报价子窗体.Controls("类似品").Value
xlBook.Application.Cells(I + 14, 7).Value = Me.报价子窗体.Controls("报价策略").Value
xlBook.Application.Cells(I + 15, 7).Value = Me.报价子窗体.Controls("备注").Value
Next
xlBook.SaveAs CurrentProject.Path + "\制造可行性评估表1.xls" '变动:另存为不同的文件名,
Set xlApp = Nothing
Set xlBook = Nothing
End Sub
|
|