2010-11-02 205 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