VB中打开excel
我有个文件夹叫D:\hao,里面有两个EXCEL,分别叫1.xls和2.xls我在2.xls表中输入宏代码,让2.xls的单元格a1的值等于1.xls中a1的值但是不对,...
我有个文件夹叫D:\hao,里面有两个EXCEL,分别叫1.xls和2.xls
我在2.xls表中输入宏代码,让2.xls的单元格a1的值等于1.xls中a1的值
但是不对,请指出哪里不对啊,帮忙修改下,谢谢
Dim xlApp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Private Sub Command1_Click()
Set xlApp = New Excel.Application
xlApp.Visible = True
Set xlbook = xlApp.Workbooks.Open("d:\hao\1.xls")
Set xlsheet = xlbook.Worksheets(1)
xlsheet.Cells(1, 1) = "23"
workbooks(2).sheets(1).cells(1,1)= xlsheet.Cells(1, 1)
End Sub 展开
我在2.xls表中输入宏代码,让2.xls的单元格a1的值等于1.xls中a1的值
但是不对,请指出哪里不对啊,帮忙修改下,谢谢
Dim xlApp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Private Sub Command1_Click()
Set xlApp = New Excel.Application
xlApp.Visible = True
Set xlbook = xlApp.Workbooks.Open("d:\hao\1.xls")
Set xlsheet = xlbook.Worksheets(1)
xlsheet.Cells(1, 1) = "23"
workbooks(2).sheets(1).cells(1,1)= xlsheet.Cells(1, 1)
End Sub 展开
1个回答
展开全部
下标越界了吧?
呵呵:
Dim xlApp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Private Sub Command1_Click()
Set xlApp = New Excel.Application
xlApp.Visible = True
Set xlbook = xlApp.Workbooks.Open("d:\hao\1.xls")
Set xlsheet = xlbook.Worksheets(1)
xlsheet.Cells(1, 1) = "23"
sheets(1).cells(1,1)= xlsheet.Cells(1, 1)
End Sub
呵呵:
Dim xlApp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Private Sub Command1_Click()
Set xlApp = New Excel.Application
xlApp.Visible = True
Set xlbook = xlApp.Workbooks.Open("d:\hao\1.xls")
Set xlsheet = xlbook.Worksheets(1)
xlsheet.Cells(1, 1) = "23"
sheets(1).cells(1,1)= xlsheet.Cells(1, 1)
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询