gpt4 book ai didi

vba - 如何删除将信息保存到剪贴板的提示?

转载 作者:行者123 更新时间:2023-12-02 21:26:53 26 4
gpt4 key购买 nike

我有一个 VBA 脚本,允许我选择一个文件,然后从该文件复制一个范围并将其粘贴到目标工作表中。然而,每次我这样做时都会打开源文件,然后关闭,这会提示我是否要将信息保存在剪贴板上。

我不知道直接复制数据而不打开源Excel是否会更好。

Option Explicit

Sub DCDatabaseCopy()
Dim vFile As Variant
Dim wbCopyTo As Workbook
Dim wsCopyTo As Worksheet
Dim wbCopyFrom As Workbook
Dim wsCopyFrom As Worksheet
Dim DCRowCount As Integer

Set wbCopyTo = ActiveWorkbook
Set wsCopyTo = ActiveSheet

'-------------------------------------------------------------
'Open file with data to be copied

vFile = Application.GetOpenFilename("Excel Files (*.*)," & "*.*", 1, "Select Excel File", "Open", False)

'If Cancel then Exit
If TypeName(vFile) = "Boolean" Then
Exit Sub
Else
Set wbCopyFrom = Workbooks.Open(vFile)
Set wsCopyFrom = wbCopyFrom.Worksheets(1)
End If

'--------------------------------------------------------------
'Copy Range
DCRowCount = wsCopyFrom.Range("A1", wsCopyFrom.Range("A1").End(xlDown)).Rows.Count

wsCopyFrom.Range("A1:G" & DCRowCount).Copy
wsCopyTo.Range("A2").PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False

'Close file that was opened
wbCopyFrom.Close SaveChanges:=False
End Sub

最佳答案

在关闭工作簿之前运行:

wbCopyFrom.Application.CutCopyMode = False

这将清除剪贴板。

关于vba - 如何删除将信息保存到剪贴板的提示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42829026/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com