Título: Listview A Excel (Aliner celda)
Publicado por: TheGhost(Z) en 13 Julio 2007, 23:30 pm
Holas, veran estoy exportando el contenido de un Listview a EXcel. Tengo un '' problema al Aliner las celdasIzqueirda, centrarm, derecha gracias por la yuda desde ya.. Private Sub ExportarListadoMSExcel() Dim AppExcel As Object Set AppExcel = CreateObject("Excel.application") With AppExcel .Visible = True .Workbooks.Add '' Agregamos un Libro Nuevo
Dim nFila As Integer nFila = 1 '' Agregos los titulos a nuestra columnas .Cells(nFila, 1) = "Id" .Cells(nFila, 2) = "Pais" .Cells(nFila, 3) = "Estado" Dim i As Long For i = 1 To Me.ListView1.ListItems.Count nFila = nFila + 1 .Cells(nFila, 1) = Me.ListView1.ListItems(i).Text .Cells(nFila, 2) = Me.ListView1.ListItems(i).ListSubItems(1).Text .Cells(nFila, 3) = Me.ListView1.ListItems(i).ListSubItems(2).Text Next i .range("A1:C1").Font.Bold = True .range("A1:C1").Interior.Color = RGB(192, 200, 200) .Cells.EntireColumn.AutoFit
'' ************* ERROR AL ALINEAR ayuda porfa.. ********************** .Range("C1").TextAlign = fmTextAlignCenter .Range("A1:H1").HorizontalAlignment = xlCenter .cell(1,).TextAlign = fmTextAlignCenter '' ************************************************
.ActiveWorkbook.SaveAs App.Path & "listado.xls" ''Guardas la hoja actual
End With
End Sub
Título: Re: Listview A Excel (Aliner celda)
Publicado por: Sancho.Mazorka en 15 Julio 2007, 05:15 am
Sino me equivoco estas haciendo una aplicacion para exportar a diferentes aplicaciones una base de datos o unos datos ingresados en una FlexiGrid, yo te ayude en la de SQL pero de Excel ni idea todavia, perdon! Sancho.Mazorka :¬¬
Título: Re: Listview A Excel (Aliner celda)
Publicado por: TheGhost(Z) en 19 Julio 2007, 04:45 am
Hola si alguien sabe alinear una celda de excel desde vb. Me han pasado un codigo: .Range("B4:L4").HorizontalAlignment = True Pero no alinea nada..
Título: Re: Listview A Excel (Aliner celda)
Publicado por: Sancho.Mazorka en 19 Julio 2007, 23:34 pm
Tu aqui tienes error en la linea que te voy a marcar, ya que si no existe un funcion te pide 1 parametro no puede colocarle 2, o colocar una "," sin poner el 2 parametro porque da error: Private Sub ExportarListadoMSExcel() Dim AppExcel As Object Set AppExcel = CreateObject("Excel.application") With AppExcel .Visible = True .Workbooks.Add '' Agregamos un Libro Nuevo Dim nFila As Integer nFila = 1 '' Agregos los titulos a nuestra columnas .Cells(nFila, 1) = "Id" .Cells(nFila, 2) = "Pais" .Cells(nFila, 3) = "Estado" Dim i As Long For i = 1 To Me.ListView1.ListItems.Count nFila = nFila + 1 .Cells(nFila, 1) = Me.ListView1.ListItems(i).Text .Cells(nFila, 2) = Me.ListView1.ListItems(i).ListSubItems(1).Text .Cells(nFila, 3) = Me.ListView1.ListItems(i).ListSubItems(2).Text Next i .range("A1:C1").Font.Bold = True .range("A1:C1").Interior.Color = RGB(192, 200, 200) .Cells.EntireColumn.AutoFit '' ************* ERROR AL ALINEAR ayuda porfa.. ********************** .Range("C1").TextAlign = fmTextAlignCenter .Range("A1:H1").HorizontalAlignment = xlCenter .cell(1,).TextAlign = fmTextAlignCenter 'ERORRRRRR .cell(1,) sacale la "," (coma) '' ************************************************ .ActiveWorkbook.SaveAs App.Path & "listado.xls" ''Guardas la hoja actual End With End Sub
y otra cosa, podes postear tu code, o pasarmelo, me interesa ayudarte y de paso me sirve a mi. rhcp_269@hotmail.com Sancho.Mazorka :¬¬
Título: Re: Listview A Excel (Aliner celda)
Publicado por: TheGhost(Z) en 31 Julio 2007, 20:59 pm
Despues de buscar y buscar consegui esto.. Si quieren mas codecs lo sacan de las Macros que se hacen en MS Excel. Espero les sirva. Private Sub Form_Load() Dim AppExcel As Excel.Application Set AppExcel = CreateObject("Excel.Application")
With AppExcel .Workbooks.Add 'Formatos With .Range("A1") .Font.Size = 18 .Value = "NUCLEAR SILO READY!" .Font.Bold = True .Font.Name = "Arial Narrow" ' , etc, etc End With ' alinear celda With .Range("C11") .HorizontalAlignment = xlLeft .VerticalAlignment = xlTop
'Reducir hasta ajustar .ReadingOrder = xlContext .WrapText = True End With
'Combinar celdas .Range("D14:E15").Merge
'Auto ajustar .Range("B:B").EntireColumn.AutoFit ' Ancho de columnas .Range("C:C").ColumnWidth = 26.71 .Range("D:D").ColumnWidth = 28.57 .Range("E:E").ColumnWidth = 10.29 'margenes de la hora de imprecion .Sheets("Hoja1").PageSetup.LeftMargin = Application.InchesToPoints(0.13) .Sheets("Hoja1").PageSetup.RightMargin = Application.InchesToPoints(0.13) .Sheets("Hoja1").PageSetup.TopMargin = Application.InchesToPoints(0.13) .Sheets("Hoja1").PageSetup.BottomMargin = Application.InchesToPoints(0.13)
'Bordes .Range("D14:G15").Borders(xlEdgeTop).LineStyle = xlContinuous .Range("D14:G15").Borders(xlEdgeTop).Weight = xlThin .Range("D14:G15").Borders(xlEdgeBottom).LineStyle = xlContinuous .Range("D14:G15").Borders(xlEdgeBottom).Weight = xlThin .Range("D14:G15").Borders(xlEdgeLeft).LineStyle = xlContinuous .Range("D14:G15").Borders(xlEdgeLeft).Weight = xlThin .Range("D14:G15").Borders(xlEdgeRight).LineStyle = xlContinuous .Range("D14:G15").Borders(xlEdgeRight).Weight = xlThin 'Proteger hoja (sin contraseña) .Sheets("Hoja1").Protect DrawingObjects:=True, Contents:=True, Scenarios:=True 'Cambiar de nombre a la hoja .Sheets("Hoja1").Name = Format(2007, "0000000000") 'Mostrar libro .Visible = True 'Guardar libro .ActiveWorkbook.SaveAs App.Path & "LOL.xls" ' imprimir libro .Sheets("Hoja1").PrintOut Copies:=1, Collate:=True 'cerrar .Quit Set AppExcel = Nothing End With End Sub
|