|
看看对你有没帮助
Sub Create_AccessProject() '用VBA语句生成Access的MDB数据库 '生成MDB文件
Dim AccessData As Object
Set AccessData = CreateObject("Access.Application")
Dim Stpath As String
Stpath = ThisWorkbook.Path & Application.PathSeparator & "data.mdb" '设定路径
If Dir(Stpath, vbDirectory) = "data.mdb" Then Exit Sub '如date.mdb已存在,则退出
AccessData.NewCurrentDatabase Stpath
Set AccessData = Nothing
'创建表格
Set cnnaccess = CreateObject("Adodb.Connection")
Set rstAnswers = CreateObject("Adodb.Recordset")
cnnaccess.Provider = "Microsoft.Jet.OLEDB.4.0"
Application.Wait Now() + TimeValue("00:00:02") '系统暂停2秒,以等待data.mdb建立成功
cnnaccess.Open "Data Source =" & Stpath & ";Jet OLEDBatabase Password=" & ""
strSQL = "Create Table myData(last_date char(8))"
rstAnswers.Open strSQL, cnnaccess
Set rstAnswers = Nothing
Set cnnaccess = Nothing
End Sub |
|