关闭工作簿中Excel VBA中的剪贴板提示 [英] Disable clipboard prompt in Excel VBA on workbook close
问题描述
当我关闭第二个工作簿(使用 Application.Close
),我得到一个提示:
是否要保存剪贴板。
VBA中是否有命令绕过此提示?
我可以提供两个选项
- 直接复制
根据您的描述,我猜你正在做一些类似
设置wb2 = Application.Workbooks.Open(YourFile.xls)
wb2.Sheets(YourSheet)。[< YourRange>]。
ThisWorkbook.Sheets(SomeSheet)。粘贴
wb2.close
如果是这种情况,您不需要通过剪贴板进行复制。此方法直接从源代码复制到目的地。
设置wb2 = Application.Workbooks.Open(YourFile.xls)
wb2.Sheets(YourSheet)。[< YourRange>]。复制ThisWorkbook.Sheets(SomeSheet)。单元格(< YourCell)
wb2.close
- 抑制提示
- 仅复制值:不要使用复制/粘贴
- Direct copy
- Suppress prompt
- To copy values only: don't use copy/paste at all
<
您可以通过设置
Application.DisplayAlerts来阻止所有警报弹出窗口= False
Dim rSrc As Range
Dim rDst As Range
设置rSrc = wb2.Sheets(YourSheet)。范围(YourRange)
设置rDst = ThisWorkbook.Sheets(SomeSheet)。单元格(YourCell)。调整大小(rSrc.Rows.Count ,rSrc.Columns.Count)
rDst = rSrc.Value
I have an Excel workbook, which using VBA code that opens another workbook, copies some data into the original, then closes the second workbook.
When I close the second workbook (using Application.Close
), I get a prompt for:
Do you want to save the clipboard.
Is there a command in VBA which will bypass this prompt?
I can offer two options
Based on your description I'm guessing you are doing something like
Set wb2 = Application.Workbooks.Open("YourFile.xls")
wb2.Sheets("YourSheet").[<YourRange>].Copy
ThisWorkbook.Sheets("SomeSheet").Paste
wb2.close
If this is the case, you don't need to copy via the clipboard. This method copies from source to destination directly. No data in clipboard = no prompt
Set wb2 = Application.Workbooks.Open("YourFile.xls")
wb2.Sheets("YourSheet").[<YourRange>].Copy ThisWorkbook.Sheets("SomeSheet").Cells(<YourCell")
wb2.close
You can prevent all alert pop-ups by setting
Application.DisplayAlerts = False
[Edit]
Dim rSrc As Range
Dim rDst As Range
Set rSrc = wb2.Sheets("YourSheet").Range("YourRange")
Set rDst = ThisWorkbook.Sheets("SomeSheet").Cells("YourCell").Resize(rSrc.Rows.Count, rSrc.Columns.Count)
rDst = rSrc.Value
这篇关于关闭工作簿中Excel VBA中的剪贴板提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!