• Martes 14 de Mayo de 2024, 10:30

Autor Tema:  Como Exportar Una Bd Desde Vb A Excel  (Leído 975 veces)

criman

  • Nuevo Miembro
  • *
  • Mensajes: 9
    • Ver Perfil
Como Exportar Una Bd Desde Vb A Excel
« en: Domingo 2 de Octubre de 2005, 17:13 »
0
Tengo un formulario donde esta conectado con una base datos y puedo exportalo a word todos sus campos, pero ahora me gustaria aprender a exportar a excel aqui les dejo el codigo para word... ojala que me puedan ayudar...

Private Sub Command5_Click()

Dim WordApp As Word.Application
Dim prueba As Word.Document
Dim sel As Word.Selection

Set Db = Adodc1.Recordset
Set WordApp = New Word.Application

    On Error Resume Next
        WordApp.Documents.Add
        Set prueba = WordApp.ActiveDocument
        Set sel = WordApp.Selection
        Set til = WordApp.Selection
     
        til.Text = "Servicios no realizados Delegación: " & Combo1.Text
        til.MoveDown
        til.Text = "Tarifa Seleccionada: " & Combo3.Text
        til.MoveDown
     
       
        prueba.PageSetup.Orientation = wdOrientLandscape
        sel.Font.Size = 7.5
        prueba.Tables.Add Range:=sel.Range, NumRows:=1, NumColumns:=12
       
        sel.Text = "Servicio"
        sel.MoveRight unit:=12
       
        sel.Text = "Nombre"
        sel.MoveRight unit:=12
       
        sel.Text = "Dirección"
        sel.MoveRight unit:=12
       
        sel.Text = "Delegación"
        sel.MoveRight unit:=12
       
        sel.Text = "Tarifa"
        sel.MoveRight unit:=12
       
        sel.Text = "Const"
        sel.MoveRight unit:=12
               
        sel.Text = "Medidor"
        sel.MoveRight unit:=12
       
        sel.Text = "Fact"
        sel.MoveRight unit:=12
       
        sel.Text = "Pont cont"
        sel.MoveRight unit:=12
               
        sel.Text = "Pont punt"
        sel.MoveRight unit:=12
       
        sel.Text = "Estado"
        sel.MoveRight unit:=12

        sel.Text = "Prpied medid"
        sel.MoveRight unit:=12
        Do Until Db.EOF
           
         
            sel.TypeText Text:=Db!SERVICIO
            sel.MoveRight unit:=12
           
            sel.TypeText Text:=Db!NOMBRE
            sel.MoveRight unit:=12
           
            sel.TypeText Text:=Db!DIRECCION
            sel.MoveRight unit:=12
           
            sel.TypeText Text:=Db!NOMBRE_DELEGACION
            sel.MoveRight unit:=12
           
            sel.TypeText Text:=Db!DESC_TARIFA
            sel.MoveRight unit:=12
           
            sel.TypeText Text:=Db!CONSTANTE_A
            sel.MoveRight unit:=12
           
            sel.TypeText Text:=Db!MEDIDOR
            sel.MoveRight unit:=12
           
            sel.TypeText Text:=Db![SUM(CONSUMO_FACTURADO)]
            sel.MoveRight unit:=12
           
            sel.TypeText Text:=Db!POTENCIA_CONTRATADA
            sel.MoveRight unit:=12
           
            sel.TypeText Text:=Db!POTENCIA_PUNTA_CONTRATADA
            sel.MoveRight unit:=12
           
            sel.TypeText Text:=Db!ESTADO_CORTE
            sel.MoveRight unit:=12
           
            sel.TypeText Text:=Db!ESTADO_MEDIDOR
            sel.MoveRight unit:=12
           
            Db.MoveNext
            Loop
           


 
    WordApp.Visible = True
    Set WordApp = Nothing