来自MS Access Database11的查询可用,并在a(刷新ODBC)导致下标超出范围错误时刷新。我不知道该怎么做。谢谢你:)。
Private Sub Workbook_Open()
Dim sR As String
Dim sFile As String
Sheets("annovar").Activate
Range("A1").Select
sR = MsgBox("Clear the annovar sheet for new data?", vbQuestion + vbYesNo + vbDefaultButton2)
If sR = vbYes Then
Application.ScreenUpdating = False
On Error Resume Next
Application.DisplayAlerts = False
Sheets("annovar").UsedRange.Clear
ChDrive "N:\Torrent\Setup\Clinical"
ChDir "N:\Torrent\Setup\Clinical"
On Error GoTo 0
sFile = Application.GetOpenFilename _
(FileFilter:="Text Files, *.txt", MultiSelect:=False)
Workbooks.OpenText Filename:=sFile, Origin:=437, StartRow:=1, DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
FieldInfo:=Array(Array(1, 1), Array(2, 1), _
Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), Array(9, 1), _
Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1), Array(15, 1), Array( _
16, 1), Array(17, 1), Array(18, 1), Array(19, 1), Array(20, 1), Array(21, 1), Array(22, 1), _
Array(23, 1), Array(24, 1), Array(25, 1), Array(26, 1), Array(27, 1), Array(28, 1), Array( _
29, 1), Array(30, 1), Array(31, 1), Array(32, 1), Array(33, 1), Array(34, 1), Array(35, 1), _
Array(36, 1), Array(37, 1), Array(38, 1), Array(39, 1), Array(40, 1), Array(41, 1), Array( _
42, 1), Array(43, 1), Array(44, 1), Array(45, 1), Array(46, 1), Array(47, 1), Array(48, 1), _
Array(49, 1), Array(50, 1), Array(51, 1), Array(52, 1), Array(53, 1), Array(54, 1), Array( _
55, 1)), TrailingMinusNumbers:=True
ActiveWorkbook.Sheets(1).UsedRange.Copy
ThisWorkbook.Sheets("annovar").Range("A1").PasteSpecial
Application.CutCopyMode = False
ActiveWorkbook.Close False
Sheets("annovar").Activate
ActiveSheet.Range("A1").Select
Application.ScreenUpdating = True
End If
'Refresh ODBC connection
ActiveWorkbook.Connections("Query from MS Access Database11").refresh
End Sub