654380491
hola@carlosdk.com
Login
[miniorange_social_login]

Login with your site account

Lost your password?

Carlos DK Carlos DK
  • Inicio
  • Kit digital
  • Universo Dk
  • Blog
  • Contacto
Back
  • Inicio
  • Kit digital
  • Universo Dk
  • Blog
  • Contacto
  • Home
  • Blog
  • Tutoriales formativos
  • error 1004 error en el metodo range del objeto worksheet – Vb6

Tutoriales formativos

18 Ago

error 1004 error en el metodo range del objeto worksheet – Vb6

  • By Carlos Dk
  • In Tutoriales formativos
  • 5 comments

Es posible que si habeis buscado una manera de leer un excel por internet, os hayais encontrado con un problema de este tipo, solo hay que darle el objeto para solucionarlo, os dejo el código para que veais el cambio:

varMatriz = xlHoja.Range(xlHoja.Cells(1, 1),  xlHoja.Cells(lngUltimaFila, 1))

Si quereis ver el código completo podeis verlo desde aquí:

Private Sub LeerExcel()

‘dimensiones
Dim xlApp As Excel.Application
Dim xlLibro As Excel.Workbook
Dim xlHoja As Excel.Worksheet
Dim varMatriz As Variant
Dim lngUltimaFila As Long

‘abrir programa Excel
Set xlApp = New Excel.Application
‘xl.Visible = True

‘abrir el archivo Excel
‘(archivo en la misma carpeta)
Set xlLibro = xlApp.Workbooks.Open(App.Path & “\prueba.xls”, True, True, , “”)
Set xlHoja = xlApp.Worksheets(“Hoja1”)

‘1. Si conoces el rango a leer
‘varMatriz = xlHoja.Range(“A1:C10”).Value

‘2. Si no conoces el rango
lngUltimaFila = _
Columns(“A:A”).Range(“A65536”).End(xlUp).Row

varMatriz = xlHoja.Range(xlHoja.Cells(1, 1), _
xlHoja.Cells(lngUltimaFila, 1))

‘utilizamos los datos…
txtLlamadas.Text = varMatriz(10, 1)

‘cerramos el archivo Excel
xlLibro.Close SaveChanges:=False
xlApp.Quit

‘reset variables de los objetos
Set xlHoja = Nothing
Set xlLibro = Nothing
Set xlApp = Nothing

End Sub

Espero que os sirva! Un saludo!

Tags:excelvb6visual basic
  • Share:
Carlos Dk

You may also like

Crear categorías y configurar menú en WordPress en 4 min.

  • marzo 3, 2019
  • by Carlos Dk
  • in Tutoriales formativos
Crear categoría y menú WordPress Es indispensable en una nueva instalación de WordPress, crear las...
Instalar tema en WordPress en 2 pasos
febrero 23, 2019
Actualizar MySQL 5.1 a 5.6 en CentOS 6.9 con Plesk como panel
octubre 20, 2018
Recorrer todos los objetos de una capa o del DOM completo con JQuery
diciembre 22, 2014

    Comments

  1. edwin
    abril 11, 2020

    Private Sub Texvalor_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)

    If KeyCode = 13 Then

    x = MsgBox(“Desea Ingresar Esta Informacion”, vbYesNo, “Ingresar Datos”)

    If x = vbYes Then

    Dim base As Worksheet
    Set base = Sheets(“base”)
    If Me.Optioningreso.Value = True Then
    aqui tengo el problema : base.Range(“1000000”).End(xlUp).Offset(1, 0).Select

    ActiveCell(1, 1).Value = “Ingreso”
    ActiveCell(1, 2).Value = CDate(Me.Textfecha)
    ActiveCell(1, 3).Value = Me.Combotipo_cuenta.Text
    ActiveCell(1, 4).Value = Me.Textconcepto.Text
    ActiveCell(1, 5).Value = VBA.CCur(Me.Texvalor)
    ActiveCell(1, 7).Value = Month(Me.Textfecha)
    ActiveCell(1, 8).Value = Year(Me.Textfecha)

    Else

    base.Range(“300000”).End(xlUp).Offset(1, 0).Select

    ActiveCell(1, 1).Value = “Ingreso”
    ActiveCell(1, 2).Value = CDate(Me.Textfecha)
    ActiveCell(1, 3).Value = Me.Combotipo_cuenta.Text
    ActiveCell(1, 4).Value = Me.Textconcepto.Text
    ActiveCell(1, 6).Value = VBA.CCur(Me.Texvalor)
    ActiveCell(1, 7).Value = Month(Me.Textfecha)
    ActiveCell(1, 8).Value = Year(Me.Textfecha)

    End If

    End If

    End If

    End Sub me presenta un error en el objeto base.range…tengo window 7 me podria ayudar? muchisimas gracias

    Responder
    • Carlos Dk
      abril 12, 2020

      Mira el código que se propone de ejemplo:
      1. Si conoces el rango a leer
      ‘varMatriz = xlHoja.Range(«A1:C10»).Value

      ‘2. Si no conoces el rango
      lngUltimaFila = _
      Columns(«A:A»).Range(«A65536»).End(xlUp).Row

      Quizás te arroje algo de luz 😉

      Responder
  2. edinson
    mayo 19, 2022

    Sub ir_BD()
    Sheets(“BD”).Select

    End Sub

    Sub grabar()
    If Range(“D5”).Value = Empty Then
    MsgBox (“datos vacios”)
    Exit Sub

    End If

    Sheets(“BD”).Select

    Range(“B5”).EntireRow.Insert————-(aqui me presenta error en el metodo de insect range) solucion

    Sheets(“INICIO”).Select

    ‘CODIGO
    Range(“D5”).Copy
    Sheets(“BD”).Select
    Range(“C5”).PasteSpecial xlPasteValues
    Sheets(“INICIO”).Select

    ‘FECHA DE INGRESO
    Range(“G5”).Copy
    Sheets(“BD”).Select
    Range(“D5”).PasteSpecial xlPasteValues
    Sheets(“INICIO”).Select

    ‘DESCRIPCION
    Range(“D7”).Copy
    Sheets(“BD”).Select
    Range(“E5”).PasteSpecial xlPasteValues
    Sheets(“INICIO”).Select

    ‘UBICACION
    Range(“G7”).Copy
    Sheets(“BD”).Select
    Range(“F5”).PasteSpecial xlPasteValues
    Sheets(“INICIO”).Select

    ‘ESPECIFICACION
    Range(“D9”).Copy
    Sheets(“BD”).Select
    Range(“G5”).PasteSpecial xlPasteValues
    Sheets(“INICIO”).Select

    limpiar

    End Sub

    Sub limpiar()
    Range(“D5”).Value = Empty
    Range(“G5”).Value = Empty
    Range(“D7”).Value = Empty
    Range(“G7”).Value = Empty
    Range(“D9”).Value = Empty

    End Sub

    Sub eliminar()
    Sheets(“BD”).Select
    Range(“B5”).EntireRow.Delete

    End Sub

    Responder
    • Carlos Dk
      agosto 1, 2022

      Revisa las comillas y demás. Este código es del año 1 DC, así que es posible que ya no funcione…

      Responder

Leave A Reply Cancelar la respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Busca en la web

Recomiendo

Software ERP empresarial

Categorías

  • Miscelanea (129)
  • Tutoriales formativos (622)

Ponte en contacto

+34 654380491

hola@carlosdk.com

Torre del Mar (Málaga)

Enlaces rápidos

  • Universo Dk
  • Contacto
  • Blog

Soy social

  • Twitter
  • Linkedin
  • Youtube

Newsletters

Suscríbete para enterarte de lo último que estoy haciendo. No lo usaré para enviarte SPAM inútil 😉

Esta web la he diseñado con cariño en Andalucía por Carlos Dk