Visual Basic - Abrir dos ficheros excel

Life is soft - evento anual de software empresarial
 
Vista:

Abrir dos ficheros excel

Publicado por Miguel (4 intervenciones) el 17/09/2007 10:56:03
Buenos dias:

Tengo que abrir dos ficheros excel pero utilizando macros de excel. Necesito coger los datos de un fichero y pasarlos a la aplicacion en la que estoy. He conseguido abrir el fichero externo, pero no soy capaz de averiguar como copiar los datos en una hoja que se llama Centro de la aplicacion.

' ... abrimos el fichero externo....
Workbooks.Open Filename:="C:\Exportacion.XLS"
Worksheets("Exportacion").Select
' ... he cogido un dato de los que necesito
nTipoCentro = Worksheets("Exportacion").Range("F2")
' y ahora quiero compiarlo en la hoja centro de la aplicacion que tengo

Gracias por vuestra atención y a ver si alguno sabe como hacerlo
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:Abrir dos ficheros excel

Publicado por csdk (127 intervenciones) el 20/09/2007 05:41:39
Dim LibroTrabajo As New Excel.Application
Dim Fichero As Excel.Workbook
MousePointer = 2
Set LibroTrabajo = New Excel.Application
Set Fichero = LibroTrabajo.Workbooks.Open(App.Path & "\C.xlt")
LibroTrabajo.Visible = True
With LibroTrabajo
.Cells(8, 5).Value = TXT_ID.Text
.Cells(9, 5).Value = Text2.Text
.Cells(10, 5).Value = Text3.Text & " CARGO " & Text4.Text
.Cells(11, 5).Value = Text5.Text & " " & Text10.Text & " MUNICIPIO " & Text6.Text
.Cells(12, 5).Value = Text7.Text & " E-MAIL " & Text8.Text
'listado2
.Cells(8, 13).Value = Text1.Text
.Cells(9, 14).Value = Text11.Text
.Cells(14, 2).Value = Text9.Text
.Cells(48, 2).Value = ATH_USERNAME & " " & ATH_USERLASTNAME
.Cells(53, 2).Value = ATH_USERMAIL
.Cells(44, 13).Value = "TOTAL " & tm
.Cells(50, 2).Value = ATH_Area
.Cells(52, 2).Value = "Tel. " & ATH_PHONE & " Ext. " & ATH_EXT
'conexion cotizacion
Call conex
RST_Cat.Source = "INSERT INTO cotizacion VALUES(" & c & "," & cl & "," & Text1.Text & "," & cvlv & ",'" & Text14.Text & "','" & 0 & "','" & Text9.Text & "','" & tm & "')"
RST_Cat.ActiveConnection = ADOCONN
RST_Cat.Open
desconectar
'****************************************************************************************
'productos
'*****************************************************************************************
' For i = 9 To 17
' .Cells(i, 5).HorizontalAlignment = xlLeft
' Next i
i2 = 1

For i = 21 To (rw + 19)
cvcot = ID("Ventas_Cotizacion", "id")
cp = bcotp(Frm_cotizacion.Spreadsheet1.Cells(i2, 2).Value)
.Cells(i, 2).Value = Frm_cotizacion.Spreadsheet1.Cells(i2, 1).Value '
.Cells(i, 5).Value = Frm_cotizacion.Spreadsheet1.Cells(i2, 2).Value 'codigo
.Cells(i, 7).Value = Frm_cotizacion.Spreadsheet1.Cells(i2, 3).Value 'sescripcion
.Cells(i, 12).Value = Frm_cotizacion.Spreadsheet1.Cells(i2, 4).Value 'unidad
.Cells(i, 13).Value = Frm_cotizacion.Spreadsheet1.Cells(i2, 5).Value 'cantidad
.Cells(i, 14).Value = Frm_cotizacion.Spreadsheet1.Cells(i2, 6).Value 'precio
.Cells(i, 16).Value = Frm_cotizacion.Spreadsheet1.Cells(i2, 7).Value 'importe
conex
RST_Cat.Source = "INSERT INTO ventas_cotizacion VALUES(" & cvcot & "," & c & "," & cp & "," & Frm_cotizacion.Spreadsheet1.Cells(i2, 6).Value & "," & Frm_cotizacion.Spreadsheet1.Cells(i2, 5).Value & ",'" & 0 & "','" & 0 & "')"
RST_Cat.ActiveConnection = ADOCONN
RST_Cat.Open
desconectar
i2 = i2 + 1
Next i
End With
LibroTrabajo.ActiveSheet.Protect "csdksol"
LibroTrabajo.Sheets("Hoja1").Name = Text11.Text

LibroTrabajo.ActiveWindow.SelectedSheets.PrintPreview
MousePointer = 0
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