当我关闭工作簿时,如何在 excel vba 中禁用剪贴板提示?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21140789/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I disable the clipboard prompt in excel vba when I close the workbook?
提问by SRoy
So I'm working with multiple workbooks from which I copy all the data from Sheet1 from each one into their respective sheet on the master workbook. After I do that, I have the multiple workbooks encoded to close. However, an annoying prompt asking if I want to keep the copied data on clipboard consistently pops up and I want to either have it not pop up or when it does, I want "No" to be automatically chosen.
因此,我正在处理多个工作簿,从中我将 Sheet1 中的所有数据从每个工作簿复制到主工作簿上各自的工作表中。完成此操作后,我将多个工作簿编码为关闭。但是,会弹出一个烦人的提示,询问我是否要始终将复制的数据保留在剪贴板上,我希望它不弹出,或者当它弹出时,我希望自动选择“否”。
I know there's a similar question that's been asked but it hasn't worked for me and I'm thinking it's because I have a rectangular area of data instead of just a column? I really new at vba but I tried messing around with the code in Disable clipboard prompt in Excel VBA on workbook closebut I've had no luck.
我知道有人问过一个类似的问题,但它对我没有用,我想这是因为我有一个矩形的数据区域,而不仅仅是一列?我真的是 vba 新手,但我尝试在关闭工作簿时处理 Excel VBA中禁用剪贴板提示中的代码,但我没有运气。
Here's my original code:
这是我的原始代码:
Sub CFM56copydata()
Dim wbk As Workbook
'The workbook is opened using the text from a textbox in a userform i.e:
strFirstFile = Userform1.dog.Text
Set wbk = Workbooks.Open(strFirstFile)
With wbk.Sheets("Sheet1")
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
End With
Set wbk2 = ThisWorkbook
wbk2.Sheets("dog").Range("A1").Insert
wbk.Close
End Sub
and here's how I tried to tweak it so I avoided using the clipbaord at all. (Didn't work, gives me a debug error on line 12)
这是我尝试调整它的方式,因此我完全避免使用 clipbaord。(不起作用,在第 12 行给了我一个调试错误)
Sub fix()
Dim wbk As Workbook
strFirstFile = Userform1.CFM56path.Text
Set wbk = Workbooks.Open(strFirstFile)
Set wbk2 = ThisWorkbook
Dim rSrc As Range
Dim rDst As Range
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Set rSrc = Selection
Set rDst = wbk2.Sheets("dog").Cells("A1").Resize(rSrc.Rows.Count, rSrc.Columns.Count)
rDst = rSrc
wbk.Close
End Sub
回答by Netloh
It should work if you change your wbk.Close
statement to:
如果您将wbk.Close
语句更改为:
Application.DisplayAlerts = False
wbk.Close
Application.DisplayAlerts = True
回答by ron
If the clipboard prompt is the problem, just empty it after your done pasting.
如果剪贴板提示是问题所在,请在完成粘贴后将其清空。
wbk2.Sheets("dog").Range("A1").Insert
Application.CutCopyMode = False
wbk.Close