Visual Basic - Activar Excel

Life is soft - evento anual de software empresarial
 
Vista:

Activar Excel

Publicado por Rafael Yañez (1 intervención) el 11/06/2001 18:08:46
¿Cómo puedo abrir un libro de Excel en una ventana de Excel previamente cargada? Es decir, si ya tengo Excel abierto, ¿cómo puedo cargar un nuevo libro desde mi aplicación de Visual Basic?
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Activar Excel

Publicado por jcnr (22 intervenciones) el 28/06/2001 18:29:50
Public Function AbreWorbook(sWorkbook As String, Optional CrearWorkbook As Boolean = False, Optional Visible As Boolean = False) As Boolean

'PARAMETROS
' sWorkbook = cadena que indica la ruta donde se encuentra el workbook
' CrearWorkbook = True si se quiere crear un Workbook en blanco
' Visible = True si se quiere ver el Excel

' La función devuelve True si todo se ha echo correctamente
On Error Resume Next

Dim bolEnWorkbooks As Boolean
Dim bolAux As Boolean
Dim bolExiste As Boolean
Dim worAux As Workbook
Dim strAux As String

bolAux = True
gApp.ScreenUpdating = Visible
gApp.Interactive = Visible
bolEnWorkbooks = False
bolExiste = False
strAux = Dir(sWorkbook)

If strAux <> "" Then
bolExiste = True
For Each worAux In gApp.Workbooks
If worAux.Name = strAux Then
bolEnWorkbooks = True
Exit For
End If
Next
End If

If bolExiste Then
'Existe y lo activamos
If bolEnWorkbooks Then
gApp.Workbooks(strAux).Activate
Set gLibro = gApp.ActiveWorkbook
Else
Set gLibro = gApp.Workbooks.Open(sWorkbook)
End If
Else 'NO EXISTE
If CrearWorkbook Then
gApp.Workbooks.Add
gApp.ActiveWorkbook.SaveAs sWorkbook
Set gLibro = gApp.ActiveWorkbook
Else
If err.Number <> 0 Then
err.Clear
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar