Excel(2007)VBA COpy&糊

时间:2010-11-02 18:13:45

标签: vba excel-2007 paste

我正在尝试将价目表从一个工作簿更新到另一个工作簿,除非我不想向客户发送主价格表中的宏...

Master将最终为每个供应商提供一个选项卡。

主副本将在没有宏的情况下发送给客户..

这是我现在的代码..

我一直收到错误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

任何想法?前进与前进如果你必须取笑我,但我需要一个答案&amp;我的一切都没有工作......

1 个答案:

答案 0 :(得分:1)

发生这种情况的原因是因为您的mXLCopy.Sheets(WhichFile).Delete命令正在清除剪贴板。

您必须重新排列代码,方法是先删除并重新创建工作表,然后再复制要粘贴的范围。

希望这有帮助,快乐