【发布时间】:2015-08-02 23:06:18
【问题描述】:
我正在尝试编写在 4 个不同数据库中导入 4 个不同文件的代码。我想知道是否有一种方法可以通过使用循环来使这个过程变得更短和更简单?我尝试了一个,但我不知道如何将一个文件定向到另一个数据库。
Option Compare Database
Option Explicit
Private Sub Command5_Click()
Dim StockPath As String
Dim WipsPath As String
Dim CcaPath As String
Dim EpsPath As String
StockPath = "F:\370\Hyperviseur\SITUATIE\Macro\Stock_getdata.xlsm"
WipsPath = "F:\370\Hyperviseur\SITUATIE\Macro\Wips_getdata.xlsm"
CcaPath = "F:\370\Hyperviseur\SITUATIE\Macro\SLAcc.xls"
EpsPath = "F:\370\Hyperviseur\SITUATIE\Macro\eps.xlsm"
If FileExist(StockPath) Then
DoCmd.TransferSpreadsheet acImport, , "Stock_CC", StockPath, True
Else
MsgBox "Bestanden niet gevonden."
End If
If FileExist(WipsPath) Then
DoCmd.TransferSpreadsheet acImport, , "Wips_CC", WipsPath, True
Else
MsgBox "Bestanden niet gevonden."
End If
If FileExist(CcaPath) Then
DoCmd.TransferSpreadsheet acImport, , "CCA_cc", CcaPath, True
Else
MsgBox "Bestanden niet gevonden."
End If
If FileExist(EpsPath) Then
DoCmd.TransferSpreadsheet acImport, , "Eps_cc", EpsPath, True
Else
MsgBox "Bestanden niet gevonden."
End If
End Sub
Function FileExist(sTestFile As String) As Boolean
Dim lSize As Long
On Error Resume Next
'Preset length to -1 because files can be zero bytes in length
lSize = -1
'Get the length of the file
lSize = FileLen(sTestFile)
If lSize > -1 Then
FileExist = True
Else
FileExist = False
End If
End Function
【问题讨论】:
标签: arrays vba import ms-access-2010 excel-2010