Results 1 to 6 of 6
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    From Excel to DBF (2000 sr 1)

    with this pakage (tks to Wizard Hans) i import from DBF and put into excel.
    Is possible to make, with the same technique, a macro to export into a DBF file?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: From Excel to DBF (2000 sr 1)

    Does the DBF file already exist, or should the macro create a new .DBF file?

  3. #3
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: From Excel to DBF (2000 sr 1)

    Hummm.... My head...
    Is already existis, refer to this...
    Note: not is possible to write a new post and not greating the Mithic Hans, goodmornig Hans!

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: From Excel to DBF (2000 sr 1)

    The Jet OLEDB proivider for DBase doesn't allow you to write to a DBase table, so we'll have to do something else. See if the following code does what you want. I had to process the date fields since they are formatted as text in your spreadsheet.

    Sub ESPORTA_PAGATI()
    ' Change the following constant as needed
    Const strFile = "E:MACRODBF_TO_EXCELTest.dbf"
    Dim Elenco As Worksheet
    Dim wbk As Workbook
    Dim wsh As Worksheet
    Dim lngMaxRow As Long
    Dim oCell As Range

    Set Elenco = ThisWorkbook.Worksheets("L0785_PAGATI")
    Set wbk = Workbooks.Add
    Set wsh = wbk.Worksheets(1)
    Elenco.Range(Elenco.Range("A6"), Elenco.Range("S65536").End(xlUp)).Copy _
    Destination:=wsh.Range("A1")
    lngMaxRow = wsh.Range("A65536").End(xlUp).Row
    For Each oCell In wsh.Range("A2:A" & lngMaxRow)
    oCell.NumberFormat = "m/d/yyyy"
    oCell.Value = DateValue(oCell.Value)
    Next oCell
    For Each oCell In wsh.Range("I2:I" & lngMaxRow)
    oCell.NumberFormat = "m/d/yyyy"
    oCell.Value = DateValue(oCell.Value)
    Next oCell
    Application.DisplayAlerts = False
    wbk.SaveAs Filename:=strFile, FileFormat:=xlDBF4
    Application.DisplayAlerts = True
    wbk.Close SaveChanges:=False

    Set oCell = Nothing
    Set wsh = Nothing
    Set wbk = Nothing
    End Sub

  5. #5
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: From Excel to DBF (2000 sr 1)

    GREAT! But not is possible to use a similar structure (see the attach excle to>access) because i would want to make a varuiuos condition on a sigle record...
    Your code copy in one shot all record and not permit to interact with a single record. Sorry for request...
    tks BIG.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: From Excel to DBF (2000 sr 1)

    The instruction

    Elenco.Range(Elenco.Range("A6"), Elenco.Range("S65536").End(xlUp)).Copy _
    Destination:=wsh.Range("A1")

    copies the entire table into the new workbook. You can replace this with code that copies row by row; you have many examples of such code from previous requests. That would allow you to inspect each row before copying it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •