Imports data from Excel or Foxpro

H

hin87_at_yahoo.com

Hi

How can I create VBA codes to imports data from Excel spreadsheetfor
FoxPro dbf files?

I am able to export the data from Table to Excel using:
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9,
dbtable, path

When I trying using this, nothing happen:
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, dbtable,
path, True

How can I import data using VBA code? I want to control which columns
goes with which table columns.

Thanks,
H
 
N

nimarii

this is what works for me:
DoCmd.TransferSpreadsheet transfertype:=acImport, _
tablename:="tablename", _
filename:="path_here", Hasfieldnames:=True, _
Range:=importrange, SpreadsheetType:=acSpreadsheetTypeExcel9

i'm sure there's an easier way, but if i want to control what data is
imported, i alter the excel spreadsheet before i actually import it. for
example, i would delete the first column if i didn't want it to be
imported:

Dim xlapp As Excel.Application
Dim xlwb As Excel.Workbook
Dim sheet As Excel.Worksheet
Set xlapp = GetObject(, "Excel.Application")
Set xlwb = xlapp.Workbooks.Open("pathNameHere")
Set sheet = xlapp.ActiveWorkbook.Sheets(1)
With xlapp
sheet.columns(1).EntireColumn.Delete
End With
 
N

nimarii

this is what works for me:
DoCmd.TransferSpreadsheet transfertype:=acImport, _
tablename:="tablename", _
filename:="path_here", Hasfieldnames:=True, _
Range:=importrange, SpreadsheetType:=acSpreadsheetTypeExcel9

i'm sure there's an easier way, but if i want to control what data is
imported, i alter the excel spreadsheet before i actually import it. for
example, i would delete the first column if i didn't want it to be
imported:

Dim xlapp As Excel.Application
Dim xlwb As Excel.Workbook
Dim sheet As Excel.Worksheet
Set xlapp = GetObject(, "Excel.Application")
Set xlwb = xlapp.Workbooks.Open("pathNameHere")
Set sheet = xlapp.ActiveWorkbook.Sheets(1)
With xlapp
sheet.columns(1).EntireColumn.Delete
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top