¿如何从 OPEN excel 复制和粘贴信息?
¿How to copy & paste information from an OPEN excel?
我有一个自动 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 is already open. Do you want to save the changes?"。我想避免这种消息。
提前谢谢你。
感谢@Our Man in Bananas 解决方案,我得到了解决方案。
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
谢谢你的回答。
我有一个自动 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 is already open. Do you want to save the changes?"。我想避免这种消息。
提前谢谢你。
感谢@Our Man in Bananas 解决方案,我得到了解决方案。
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
谢谢你的回答。