2015-11-24 50 views
0

我必須運行一個報表,導出它,操作它,添加到相同的論壇等等。所以我想我可能只是做一個宏來做大部分工作我。錯誤438從每週關閉工作簿複製數據

我最終創建了一個帶有forumulas的excel文件,這樣我就可以使用VBA將其複製並粘貼,但是,我收到錯誤438對象不支持此屬性或方法,以wba.sheets開頭

這是代碼。

Dim wba As Workbook 
Set wba = ThisWorkbook 
Application.DisplayAlerts = False 
Dim wb As Workbook 
Set wb = Workbooks.Open("C:\Users\xxx\Documents\Custom Office Templates\xxx.xlsx") 
wb.Sheets("Sheet1").Range("A1:F18").Copy 
wba.Sheets("Sheet1").Range("F1").End(xlDown).Offset(2, -5).Paste 
wb.Close False 
Application.DisplayAlerts = True 
+0

嘗試更換'結束(xlDown)'和'端(xlUp)'。 –

+0

完成後,知道它是更清潔,但沒有知道抵消會改變。回想起來,睡眠剝奪的思想。 – Michael

回答

0
Dim wba As Workbook 
Set wba = ThisWorkbook 
Application.DisplayAlerts = False 
Dim wb As Workbook 
Set wb = Workbooks.Open("C:\Users\xxx\Documents\Custom Office Templates\xxx.xlsx")  
wb.Sheets("Sheet1").Range("A1:F18").Copy 
wba.Activate 
Sheets("Sheet1").Range("F1").End(xlDown).Offset(2, -5).Select 
Activesheet.Paste 
wb.Close False 
Application.DisplayAlerts = True 
0

使用,如果沒有什麼下文F1的,所以它通常使用更安全xlUp(如@MarcoGetrost說明)xlDown將失敗

Dim wba As Workbook, wb As Workbook 
Set wba = ThisWorkbook 

Application.DisplayAlerts = False 

Set wb = Workbooks.Open("C:\Users\xxx\Documents\Custom Office Templates\xxx.xlsx") 

wb.Sheets("Sheet1").Range("A1:F18").Copy _ 
     wba.Sheets("Sheet1").Cells(Rows.Count,"F").End(xlUp).Offset(2, -5) 

wb.Close False 

Application.DisplayAlerts = True 
相關問題