我想把excel中的数据导入到Access中在网上找了这样一段代码
dim conn
dim conn2
set conn=CreateObject("ADODB.Connection"
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDBatabase Password=;Data Source=C:\Inetpub\wwwroot\book1.mdb"
set conn2=CreateObject("ADODB.Connection"
conn2.Open "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDBatabase Password=;Extended properties=Excel 5.0;Data Source=c:\book1.xls"
sql = "SELECT * FROM [Sheet1$]"
set rs = conn2.execute(sql)
while not rs.eof
sql = "insert into book1([a],[b],[c],[d]) values('"& fixsql(rs(0)) &"','"& fixsql(rs(1)) &"','"& fixsql(rs(2)) &"','"& fixsql(rs(3)) &"')"
conn.execute(sql)
rs.movenext
wend
conn.close
set conn = nothing
conn2.close
set conn2 = nothing
function fixsql(str)
dim newstr
newstr = str
if isnull(newstr) then
newstr = ""
else
newstr = replace(newstr,"'","''"
end if
fixsql = newstr
end function
测试成功!!但他的excel路径是确定的 c:\book1.xls 怎样让路径可以选择!就象上传一样。
[此贴子已经被作者于2006-7-5 6:29:08编辑过]