【问题标题】:¿How to copy & paste information from an OPEN excel? [duplicate]¿ 如何从打开的 excel 中复制和粘贴信息? [复制]
【发布时间】:2018-12-30 21:23:07
【问题描述】:

我有一个自动 Excel (excel A),可以从另一个 Excel (excel B) 复制和粘贴信息。 我已经控制了excelB是否存在。

我想这样做:

If "workbookExcelBisopen" Then 'what can i put inside the if
   'What can i put here for make the code work
Else 
    Set ExcelB = Application.Workbooks.Open(".xlsx", False, True)
End if

Sheets("Sheet1excelB").Select

我遇到的主要问题是如果工作簿已经打开,它会显示一条消息“ExcelB 已经打开。你想保存更改吗?”。我想避免这种信息。

提前谢谢你。

【问题讨论】:

  • Set ExcelB = Application.Workbooks("nameofexcelBworkbook.xlsx")
  • 它不起作用。
  • 应该,但您之前没有提到您还需要“workbookExcelBisopen”的代码。
  • 我的意思是,如果没有 If,如果我把你提到的代码而不是“Set ExcelB = Application.Workbooks.Open(".xlsx", False, True)" 它不起作用。
  • @David_helo:这是我为您找到的另一个参考资料(使用 Google):How to quickly check if a workbook is open

标签: excel vba copy paste


【解决方案1】:

感谢@Our Man in Bananas 在 SO 中的解决方案,我得到了解决方案。

 Sub test()

        Dim wb As Workbook

        Set wb = GetWorkbook("C:\Users\dick\Dropbox\Excel\Hoops.xls")

        If Not wb Is Nothing Then
            Debug.Print wb.Name
        End If

End Sub


Public Function GetWorkbook(ByVal sFullName As String) As Workbook

    Dim sFile As String
    Dim wbReturn As Workbook

    sFile = Dir(sFullName)

    On Error Resume Next
        Set wbReturn = Workbooks(sFile)

        If wbReturn Is Nothing Then
            Set wbReturn = Workbooks.Open(sFullName)
        End If
    On Error GoTo 0

    Set GetWorkbook = wbReturn

End Function

谢谢你的回答。

【讨论】:

  • 不用担心积分,我相信这个问题是重复的,所以你可以选择你的答案并自己获得积分,或者使用标签下的删除链接删除问题。
  • 如果您不打算删除问题,请将代码添加到您的答案中,不鼓励仅链接答案
  • 我把它当作重复的
  • 谢谢...最好还是自己关闭而不是等待审核队列来完成
猜你喜欢
  • 2019-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-26
  • 1970-01-01
相关资源
最近更新 更多