necesito ayuda con VisualBasic y excel
Me gustar铆a poder trabajar con Visual Basic conta excel pero no tengo ni idea de como hacerlo.
Me pregunto si teneis alg煤n codigo que me sirva como ejemplo o si sabeis d alguna direcci贸n o manual, tutorial...
Me pregunto si teneis alg煤n codigo que me sirva como ejemplo o si sabeis d alguna direcci贸n o manual, tutorial...
Hola rodrigo lo acabo de poner en un mensaje de abajo pero si te sirve ahi te va:
Private Sub Command2_Click()
'Declaramos nuestra aplicaci贸n excel
Set mConn = New Connection
mConn.Open "DSN=TIP", "Rafael", ""
Dim ap As New Excel.Application
Dim rsexcel As Recordset
Set rsexcel = New Recordset
Dim noesn As Integer
'Creamos el documento
ap.Workbooks.Open "c:desarrollostarifariostarifario.xlt"
'Quitamos las alertas que provengan de EXCEL:
ap.DisplayAlerts = False
'A帽adimos un libro a nuestro fichero
'ap.Workbooks(1).Worksheets.Add
'y seleccionamos dicho libro
ap.Worksheets(1).Select
noesn = 0
'ap.Cells(5, 1) = ap.Cells(5, 1) & ": Celular Performance"
ap.Cells(14, 7) = Left(Trim(Me.txtfolio), 4) & ":" & Right(Trim(Me.txtfolio), 2)
ap.Cells(14, 12) = Format(Date, "mmmm d, yyyy")
While noesn < Me.MSFlexGrid1.Rows
rsexcel.Open "select * from tarifario t,promo p where t.pq_id=p.pm_id and tf_foliosiact=" + "'" + Me.MSFlexGrid1.TextMatrix(noesn, 0) + "'", mConn, adOpenKeyset, adLockOptimistic
If Not rsexcel.EOF Then
ap.Cells((noesn + 17), 2) = Trim(rsexcel!tf_nombre)
ap.Cells((noesn + 17), 5) = Trim(rsexcel!tf_numero)
ap.Cells((noesn + 17), 7) = Trim(rsexcel!pm_clvcomision)
ap.Cells((noesn + 17), 11) = Trim(rsexcel!tf_fechaacti)
ap.Cells((noesn + 17), 13) = Trim(rsexcel!pm_plan) & " " & Trim(rsexcel!pm_tipo)
End If
rsexcel.Close
noesn = noesn + 1
Wend
'Me.TXTNOMBRE = "AA"
ap.Workbooks(1).SaveAs Me.TXTRUTA & Me.TXTNOMBRE & Me.TXTEXT
'Cerramos todo
ap.Workbooks.Close
ap.Quit
Set ap = Nothing
End Sub
Saludos
Private Sub Command2_Click()
'Declaramos nuestra aplicaci贸n excel
Set mConn = New Connection
mConn.Open "DSN=TIP", "Rafael", ""
Dim ap As New Excel.Application
Dim rsexcel As Recordset
Set rsexcel = New Recordset
Dim noesn As Integer
'Creamos el documento
ap.Workbooks.Open "c:desarrollostarifariostarifario.xlt"
'Quitamos las alertas que provengan de EXCEL:
ap.DisplayAlerts = False
'A帽adimos un libro a nuestro fichero
'ap.Workbooks(1).Worksheets.Add
'y seleccionamos dicho libro
ap.Worksheets(1).Select
noesn = 0
'ap.Cells(5, 1) = ap.Cells(5, 1) & ": Celular Performance"
ap.Cells(14, 7) = Left(Trim(Me.txtfolio), 4) & ":" & Right(Trim(Me.txtfolio), 2)
ap.Cells(14, 12) = Format(Date, "mmmm d, yyyy")
While noesn < Me.MSFlexGrid1.Rows
rsexcel.Open "select * from tarifario t,promo p where t.pq_id=p.pm_id and tf_foliosiact=" + "'" + Me.MSFlexGrid1.TextMatrix(noesn, 0) + "'", mConn, adOpenKeyset, adLockOptimistic
If Not rsexcel.EOF Then
ap.Cells((noesn + 17), 2) = Trim(rsexcel!tf_nombre)
ap.Cells((noesn + 17), 5) = Trim(rsexcel!tf_numero)
ap.Cells((noesn + 17), 7) = Trim(rsexcel!pm_clvcomision)
ap.Cells((noesn + 17), 11) = Trim(rsexcel!tf_fechaacti)
ap.Cells((noesn + 17), 13) = Trim(rsexcel!pm_plan) & " " & Trim(rsexcel!pm_tipo)
End If
rsexcel.Close
noesn = noesn + 1
Wend
'Me.TXTNOMBRE = "AA"
ap.Workbooks(1).SaveAs Me.TXTRUTA & Me.TXTNOMBRE & Me.TXTEXT
'Cerramos todo
ap.Workbooks.Close
ap.Quit
Set ap = Nothing
End Sub
Saludos
