vb6.0怎么实现两个不同的过程中保存excel的命令怎么写呀
PrivateSubCommand1_Click()StaticzAsIntegerSetxlapp=CreateObject("Excel.Application")'...
Private Sub Command1_Click()
Static z As Integer
Set xlapp = CreateObject("Excel.Application") '创建EXCEL对象
xlapp.Visible = True
If z = 0 Then
Set xlbook = xlapp.workbooks.Add '新建EXCEL工件簿文件
Else
Set xlbook = xlapp.workbooks.Open("d:\test.xlsx") '打开已经存在的test.xls工件簿文件
End If
Set xlsheet = xlbook.Worksheets(1)
Set xlsapp = GetObject(, "Excel.Application")
If z = 0 Then
For i = 1 To 5
For j = 1 To 5
xlsapp.sheets("sheet1").Cells(i, j) = i * j
Next j
Next i
Else
For i = 1 To 5
For j = 1 To 5
xlsapp.sheets("sheet1").Cells(i, j) = 1
Next j
Next i
End If
xlbook.saveas = "d:\test.xlsx"
xlsapp.quit
Set xlsheets = Nothing
Set xlbook = Nothing
Set xlapp = Nothing
z = z + 1
End Sub
Private Sub Command2_Click()
slbook.save????这里怎么改呀,提示说“要求对象”。。。
End Sub
Private Sub Form_Load()
Command1.Caption = "开始"
Command2.Caption = "保存"
End Sub
还有就是command1.click中想第一次运行的时候新建一个excel,之后在运行就直接打开这个excel就行的命令怎么改,请各位大神不吝赐教。
暂时没有财富值了 ,还请各位见谅 展开
Static z As Integer
Set xlapp = CreateObject("Excel.Application") '创建EXCEL对象
xlapp.Visible = True
If z = 0 Then
Set xlbook = xlapp.workbooks.Add '新建EXCEL工件簿文件
Else
Set xlbook = xlapp.workbooks.Open("d:\test.xlsx") '打开已经存在的test.xls工件簿文件
End If
Set xlsheet = xlbook.Worksheets(1)
Set xlsapp = GetObject(, "Excel.Application")
If z = 0 Then
For i = 1 To 5
For j = 1 To 5
xlsapp.sheets("sheet1").Cells(i, j) = i * j
Next j
Next i
Else
For i = 1 To 5
For j = 1 To 5
xlsapp.sheets("sheet1").Cells(i, j) = 1
Next j
Next i
End If
xlbook.saveas = "d:\test.xlsx"
xlsapp.quit
Set xlsheets = Nothing
Set xlbook = Nothing
Set xlapp = Nothing
z = z + 1
End Sub
Private Sub Command2_Click()
slbook.save????这里怎么改呀,提示说“要求对象”。。。
End Sub
Private Sub Form_Load()
Command1.Caption = "开始"
Command2.Caption = "保存"
End Sub
还有就是command1.click中想第一次运行的时候新建一个excel,之后在运行就直接打开这个excel就行的命令怎么改,请各位大神不吝赐教。
暂时没有财富值了 ,还请各位见谅 展开
1个回答
展开全部
Win7XPUSERPROFILE文件路径同XPC:\Documents and Settings\All Users据相容易判断用户否XP操作系统通编写获取用户桌面路径代码冗麻烦代码:Dim path , getpath , allusers$
path = Environ("USERPROFILE")
allusers = Environ("ALLUSERSPROFILE")
If allusers = "C:\Documents and Settings\All Users" Then
getpath = path & "\桌面\"
Else
getpath = path & "\Desktop\"
End If获取Win7XP桌面路径
path = Environ("USERPROFILE")
allusers = Environ("ALLUSERSPROFILE")
If allusers = "C:\Documents and Settings\All Users" Then
getpath = path & "\桌面\"
Else
getpath = path & "\Desktop\"
End If获取Win7XP桌面路径
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |