在VB中如何将数据依次写入Excel中?
PrivateSubCommand1_Click()pn=projectNO.Textd1=Calendar1.Daym1=Calendar1.Monthy1=Calen...
Private Sub Command1_Click()
pn = projectNO.Text
d1 = Calendar1.Day
m1 = Calendar1.Month
y1 = Calendar1.Year
d2 = Calendar2.Day
m2 = Calendar2.Month
y2 = Calendar2.Year
st = d1 & "/" & m1 & "/" & y1
ft = d2 & "/" & m2 & "/" & y2
fp = Combo1.Text
If MsgBox("If you want to save data£¿", vbYesNo + vbExclamation, "VB save data to Excel") = vbYes Then
Set ExcelApp = CreateObject("Excel.Application")
ExcelApp.Workbooks.Add
With ExcelApp.ActiveSheet
.Range("A1:D1") = Array(pn, st, ft, fp)
MyFileName = ExcelApp.GetSaveAsFilename(, "Excel Files (*.xls), *.xls")
.SaveAs MyFileName
End With
ExcelApp.Quit
Else
projectNO.Text = ""
Combo1.Text = ""
End If
End Sub
目前实现的功能是一个Excel book显示一条记录,我想实现将第一个项目得到的po(项目号),st(开始时间),ft(结束时间),ft(完成百分比)写入第一行,第二个项目得到的内容写入第二行,以此类推,相同的项目号不需要覆盖内容,请教一下高手,谢谢! 展开
pn = projectNO.Text
d1 = Calendar1.Day
m1 = Calendar1.Month
y1 = Calendar1.Year
d2 = Calendar2.Day
m2 = Calendar2.Month
y2 = Calendar2.Year
st = d1 & "/" & m1 & "/" & y1
ft = d2 & "/" & m2 & "/" & y2
fp = Combo1.Text
If MsgBox("If you want to save data£¿", vbYesNo + vbExclamation, "VB save data to Excel") = vbYes Then
Set ExcelApp = CreateObject("Excel.Application")
ExcelApp.Workbooks.Add
With ExcelApp.ActiveSheet
.Range("A1:D1") = Array(pn, st, ft, fp)
MyFileName = ExcelApp.GetSaveAsFilename(, "Excel Files (*.xls), *.xls")
.SaveAs MyFileName
End With
ExcelApp.Quit
Else
projectNO.Text = ""
Combo1.Text = ""
End If
End Sub
目前实现的功能是一个Excel book显示一条记录,我想实现将第一个项目得到的po(项目号),st(开始时间),ft(结束时间),ft(完成百分比)写入第一行,第二个项目得到的内容写入第二行,以此类推,相同的项目号不需要覆盖内容,请教一下高手,谢谢! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询