Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 3401|回复: 12

[已解决]请帮忙看看我代码错在那里了-- GetObject使用问题

[复制链接]
发表于 2011-4-4 13:48 | 显示全部楼层 |阅读模式
附件中是在工作 表“取数2”操作,打开指定文件夹下的“河北-3月.xls”中的工作表31,然后把B15:AC22的数复制过来,请帮忙看看我代码错在那里了,提示自动化操作文件未找到。
最佳答案
2011-4-4 14:26
你的文件名有错,多了个.xls(你实际的文件名为:河北-3月.xls.xls)

新建文件夹 (2).rar

324.09 KB, 下载次数: 5

 楼主| 发表于 2011-4-4 14:03 | 显示全部楼层
回复

使用道具 举报

发表于 2011-4-4 14:22 | 显示全部楼层
Call 关闭工作簿,这个过程在哪啊,没找到啊
回复

使用道具 举报

发表于 2011-4-4 14:26 | 显示全部楼层    本楼为最佳答案   
你的文件名有错,多了个.xls(你实际的文件名为:河北-3月.xls.xls)
回复

使用道具 举报

 楼主| 发表于 2011-4-4 14:33 | 显示全部楼层
Dim WB
Sub 取数2()
Application.ScreenUpdating = False
Dim mydate
Dim m, vl, KH, zq, RQ
With ThisWorkbook.Sheets(2) '因为要打开多个文件,所以用with语句保证结果放在取数工作簿中
.Range(Cells(4, 1), Cells(1000, 5)).Clear
mydate = .Cells(1, 2)
返回年月日并取得文件控件权 (mydate)
arr = WB.Sheets(CStr(Day(mydate))).Range("B15:AC22")
ReDim brr(1 To UBound(arr), 1 To 5)
  For x = 1 To UBound(arr)
     brr(m + 1, 1) = arr(x, 1)
   brr(m + 1, 2) = arr(x, 25)
   brr(m + 1, 3) = arr(x, 26)
   brr(m + 1, 4) = arr(x, 27)
   brr(m + 1, 5) = arr(x, 28)
   m = m + 1
Next x
.Cells(4, 1).Resize(m, 5) = brr
End With
WB.Close False
Set WB = Nothing
Set ws = Nothing
Erase arr
Erase brr
Application.ScreenUpdating = True
End Sub
Sub 返回年月日并取得文件控件权(mdate As Date)
    Application.ScreenUpdating = False
    MyYear = Year(mdate)
    MyMonth = Month(mdate)
    Myday = Day(mdate)
Set WB = GetObject(ThisWorkbook.Path & "\对帐单\" & MyYear & "年\" & MyMonth & "月\" & "河北-" & MyMonth & "月.xls") '打开该月份的工资表
End Sub
请把上面代码封存成DLL文件,谢谢
回复

使用道具 举报

 楼主| 发表于 2011-4-4 15:25 | 显示全部楼层
arr = WB.Sheets(CStr(Day(mydate))).Range("B15:AC22")
ReDim brr(1 To UBound(arr), 1 To 5)
  For x = 1 To UBound(arr)
     brr(m + 1, 1) = arr(x, 1)
   brr(m + 1, 2) = arr(x, 25)
   brr(m + 1, 3) = arr(x, 26)
   brr(m + 1, 4) = arr(x, 27)
   brr(m + 1, 5) = arr(x, 28)
   m = m + 1
Next x
上面代码如何用UNION把range(B15:B22)和RANGGE(Z15:AC22)连接起来
回复

使用道具 举报

 楼主| 发表于 2011-4-4 15:34 | 显示全部楼层
arr = WB.Sheets(CStr(Day(mydate))).Range("B15:AC22")
ReDim brr(1 To UBound(arr), 1 To 5)
  For x = 1 To UBound(arr)
     brr(m + 1, 1) = arr(x, 1)
   brr(m + 1, 2) = arr(x, 25)
   brr(m + 1, 3) = arr(x, 26)
   brr(m + 1, 4) = arr(x, 27)
   brr(m + 1, 5) = arr(x, 28)
   m = m + 1
Next x
上面代码如何用UNION把range(B15:B22)和RANGGE(Z15:AC22)连接起来
回复

使用道具 举报

 楼主| 发表于 2011-4-4 15:34 | 显示全部楼层
Dim WB
Sub 取数2()
Application.ScreenUpdating = False
Dim mydate
Dim m, vl, KH, zq, RQ
With ThisWorkbook.Sheets(2) '因为要打开多个文件,所以用with语句保证结果放在取数工作簿中
.Range(Cells(4, 1), Cells(1000, 5)).Clear
mydate = .Cells(1, 2)
返回年月日并取得文件控件权 (mydate)
arr = WB.Sheets(CStr(Day(mydate))).Range("B15:AC22")
ReDim brr(1 To UBound(arr), 1 To 5)
  For x = 1 To UBound(arr)
     brr(m + 1, 1) = arr(x, 1)
   brr(m + 1, 2) = arr(x, 25)
   brr(m + 1, 3) = arr(x, 26)
   brr(m + 1, 4) = arr(x, 27)
   brr(m + 1, 5) = arr(x, 28)
   m = m + 1
Next x
.Cells(4, 1).Resize(m, 5) = brr
End With
WB.Close False
Set WB = Nothing
Set ws = Nothing
Erase arr
Erase brr
Application.ScreenUpdating = True
End Sub
Sub 返回年月日并取得文件控件权(mdate As Date)
    Application.ScreenUpdating = False
    MyYear = Year(mdate)
    MyMonth = Month(mdate)
    Myday = Day(mdate)
Set WB = GetObject(ThisWorkbook.Path & "\对帐单\" & MyYear & "年\" & MyMonth & "月\" & "河北-" & MyMonth & "月.xls") '打开该月份的工资表
End Sub
请把上面代码封存成DLL文件,谢谢
回复

使用道具 举报

 楼主| 发表于 2011-4-4 15:34 | 显示全部楼层
Dim WB
Sub 取数2()
Application.ScreenUpdating = False
Dim mydate
Dim m, vl, KH, zq, RQ
With ThisWorkbook.Sheets(2) '因为要打开多个文件,所以用with语句保证结果放在取数工作簿中
.Range(Cells(4, 1), Cells(1000, 5)).Clear
mydate = .Cells(1, 2)
返回年月日并取得文件控件权 (mydate)
arr = WB.Sheets(CStr(Day(mydate))).Range("B15:AC22")
ReDim brr(1 To UBound(arr), 1 To 5)
  For x = 1 To UBound(arr)
     brr(m + 1, 1) = arr(x, 1)
   brr(m + 1, 2) = arr(x, 25)
   brr(m + 1, 3) = arr(x, 26)
   brr(m + 1, 4) = arr(x, 27)
   brr(m + 1, 5) = arr(x, 28)
   m = m + 1
Next x
.Cells(4, 1).Resize(m, 5) = brr
End With
WB.Close False
Set WB = Nothing
Set ws = Nothing
Erase arr
Erase brr
Application.ScreenUpdating = True
End Sub
Sub 返回年月日并取得文件控件权(mdate As Date)
    Application.ScreenUpdating = False
    MyYear = Year(mdate)
    MyMonth = Month(mdate)
    Myday = Day(mdate)
Set WB = GetObject(ThisWorkbook.Path & "\对帐单\" & MyYear & "年\" & MyMonth & "月\" & "河北-" & MyMonth & "月.xls") '打开该月份的工资表
End Sub
请把上面代码封存成DLL文件,谢谢
回复

使用道具 举报

 楼主| 发表于 2011-4-4 15:36 | 显示全部楼层
请把上面代码封存成DLL文件,谢谢
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-3 20:46 , Processed in 0.626611 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表