关闭工作簿中Excel VBA中的剪贴板提示 [英] Disable clipboard prompt in Excel VBA on workbook close

查看:4243
本文介绍了关闭工作簿中Excel VBA中的剪贴板提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Excel工作簿,它使用VBA代码打开另一个工作簿,将一些数据复制到原始文件中,然后关闭第二个工作簿。



当我关闭第二个工作簿(使用 Application.Close ),我得到一个提示:


是否要保存剪贴板。


VBA中是否有命令绕过此提示?

解决方案

我可以提供两个选项


  1. 直接复制

根据您的描述,我猜你正在做一些类似

 设置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




  1. 抑制提示

  2. <

    您可以通过设置

      Application.DisplayAlerts来阻止所有警报弹出窗口= False 







    1. 仅复制值:不要使用复制/粘贴



      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

    1. Direct copy

    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
    

    1. Suppress prompt

    You can prevent all alert pop-ups by setting

    Application.DisplayAlerts = False
    


    [Edit]

    1. To copy values only: don't use copy/paste at all

    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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆