RE:Export a una hoja Excel
Uhm.. con este codigo te funciona pero solo si tienes un documento abierto
Dim objExcel As Object
'Captura de errores
On Error Resume Next
'Hace una referencia a la aplicación Excel
Set objExcel = GetObject(, "Excel.Application")
'Si nos da error significa que Excel NO esta en ejecucion
If Err.Number = 429 Then
Err.Clear
'Creamos una NUEVA instancia de Excel
Set objExcel = CreateObject("Excel.Application")
End If
' Mostrar el nombre del documento
MsgBox objExcel.WorkBooks(1).Name
Pero si tienes varios.. pues puedes buscar el Caption con Apis..
En un Boton :
Call EnumWindows(AddressOf BuscaExcel, 0)
En un Modulo :
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
Public Function BuscaExcel(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim lLength As Long
Dim strCaption As String
Dim lMenuHwnd As Long
Dim lMenuCount As Long
lLength = GetWindowTextLength(hwnd)
strCaption = String(lLength, vbNullChar)
GetWindowText hwnd, strCaption, lLength + 1
lMenuHwnd = GetMenu(hwnd)
lMenuCount = GetMenuItemCount(lMenuHwnd)
If lLength > 0 Then
If strCaption Like "*Excel*xls" Then
Form1.List1.AddItem strCaption
End If
End If
BuscaExcel = True
End Function