我试图将spredsheet数据传输到访问表。我检查工作表包含第一行中除标题之外的任何数据,如果数据不存在,则我将转移到访问表。在那里我提到ExcelApp.Visible = False,但excel工作簿在以前任何其他工作簿保持打开时打开,而在任何其他工作簿未打开时不打开。这是我的代码,
Dim objDialog As Object
Set objDialog = Application.FileDialog(3)
Dim strXls As String
'On Error GoTo errHandler
On Error Resume Next
With objDialog
.Title = "Select the Excel file to import"
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "Excel Files macros enabled", "*.xlsm", 1
.Filters.Add "All Files", "*.*", 2
.Filters.Add "Excel Files", "*.xlsx", 3
If .Show = -1 Then
StrFileName = .SelectedItems(1)
Set ExcelBook = ExcelApp.Workbooks.Open(StrFileName)
ExcelApp.Visible = False
''Define your own Range
Set rngDefine = ExcelBook.Worksheets("Data1").Range("A1:AJ1")
If IsError(ExcelApp.Match("ABC", rngDefine, 0)) Then
' MsgBox "Not found"
DoCmd.TransferSpreadsheet transfertype:=acImport, _
tablename:=tblname, _
FileName:=StrFileName, Hasfieldnames:=True, _
Range:="Data1!A:FK", SpreadsheetType:=5
Else
MsgBox "The excelfile you trying to import contains one heading ABC in the first row.Please Delete it before importing"
ExcelBook.Close SaveChanges:=False
Set ExcelBook = Nothing
ExcelApp.Quit
Set ExcelApp = Nothing
Exit Sub
End If