Sub connect_db(OSS_Name As String, PWD As String, DB_name As String, SQL_string As String, Position As String)
'On Error Resume Next
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DRIVER={sybase system 11};SRVR=" + OSS_Name + _
";DB=" & DB_name & ";UID=
WD=" + PWD, _
Destination:=Range(Position))
.Sql = Array(SQL_string)
.FieldNames = True
.RefreshStyle = xlOverwriteCells
'On Error Resume Next
.Refresh BackgroundQuery:=False
' .RefreshStyle = xlInsertDeleteCells
' .RowNumbers = False
' .FillAdjacentFormulas = False
' .RefreshOnFileOpen = False
' .HasAutoFormat = True
' .BackgroundQuery = True
' .TablesOnlyFromHTML = True
' .Refresh BackgroundQuery:=False
' .SavePassword = True
' .SaveData = True
End With
End Sub
這個(gè)就是連接到oss數(shù)據(jù)庫(kù)中的啊。
這個(gè)程序根據(jù)各地的情況肯定得稍稍改一下:你連接oss的名稱(chēng),oss數(shù)據(jù)庫(kù)的用戶名和密碼等。