2010-11-02 206 views
1

我試圖更新從一個工作簿價目表另一個除了我不想從主價格向客戶發送宏...的Excel(2007)VBA複製和粘貼

的主人最終會爲每個供應商提供一個選項卡。

主副本將被髮送給客戶,而不宏..

這裏是我的代碼的現在..

我不斷收到錯誤1004粘貼方法失敗

'Now copy from the Update Master to the Cust Master... 
mWrk = "A1:Z" & Trim(Str(TotRows)) <---TotRows is the total # of rows used 



Application.CutCopyMode = XLCopy 
Worksheets(WhichFile).Range(mWrk).Copy <-- WhichFile has the value of the sheet name.. 


Dim mXLCopy As Workbook 
Set mXLCopy = Workbooks.Open(ThisWorkbook.Path & "\Customer Master Price.xlsx") 

' See if the sheet is already there. if so delete it. 
Dim IsThere As Boolean 
IsThere = False 
For x = 1 To mXLCopy.Sheets.Count 
    If UCase(mXLCopy.Sheets(x).Name) = UCase(WhichFile) Then 
     IsThere = True 
    End If 
Next x 
Application.DisplayAlerts = False 
If IsThere Then 
    mXLCopy.Sheets(WhichFile).Delete 
End If 

' 
'Now add it & activate it.. 
mXLCopy.Sheets.Add().Name = WhichFile 
mXLCopy.Activate 

With mXLCopy.Sheets(WhichFile) 
    Range(mWrk).PasteSpecial xlPasteAll, xlPasteSpecialOperationNone <- Fails here 
End With 

Application.DisplayAlerts = True 

mXLCopy.Save 
mXLCopy.Close 
Set mRange = Nothing 
Set mXLCopy = Nothing 

任何想法的人?繼續&如果你一定要取笑我,但我需要一個答案&無礦正在...

回答

1

出現這種情況的原因是因爲你的mXLCopy.Sheets(WhichFile).Delete命令清除剪貼板。

你將不得不重新安排代碼,這樣你刪除和第一重新創建表,然後才複製的範圍將被粘貼的方式。

希望這會有所幫助,快樂吧

+0

很好!感謝朱利安的幫助。大約10分鐘前,我對刪除做了一個頓悟,正如你所說的那樣。我重新安排了兩個函數分開的代碼,並試用成功! ..我回到這裏來更新這個帖子,並找到你的答案..再次,謝謝.. – 2010-11-02 21:30:53