因此,正如您从变量名中看到的那样,这是用于莲花文件的,但是,我将它用于 csv。所以你的excel文件的结构是一样的。如果您只想将其保存为 CSV 文件,并祝您生活愉快。我知道已经 6 年了,所以我想你不再需要这个了,但可能会帮助遇到这个问题的其他人。
Dim LotusCn As Object
Dim rsLotus As Object
Dim strSql, CombFileName, GotoRange As String
Dim rsLotusFiles As DAO.Recordset
Dim rsDAO1 As DAO.Recordset
Dim strName1 As String
Set LotusCn = CreateObject("ADODB.Connection")
Set rsLotus = CreateObject("ADODB.Recordset")
strSql = "Provider=" & _ 'This is where the file is located
CurrentProject.Connection.Provider & _
";Data Source=" & Directory & _
";Extended Properties='text;HDR=YES;FMT=Delimited'"
LotusCn.Open strSql
Dim fld1 As ADODB.Field
strSql = "SELECT * FROM NUMBDATM.CSV" 'This is the file name and please open it
rsLotus.Open strSql, LotusCn, adOpenFowardOnly, adLockReadOnly, adCmdText
Set rsDAO1 = CurrentDb.OpenRecordset("NUMBDATM", _ 'This here is the table you
dbOpenTable, dbAppendOnly + dbFailOnError) want to import into
Do Until rsLotus.EOF 'Here tell it what values you want from the excel Sheet
RegNumber = rsLotus![Reg# Number]
CompanyName = rsLotus![Company Name]
SalesGrowth1 = rsLotus![Sales Growth % 1 ]
FixedAssets1 = rsLotus![Fixed Assets 1 ]
PeriodEnding1 = rsLotus![Period Ending 1 ]
TotalSales1 = rsLotus![Total Sales 1 ]
SalesGrowth2 = rsLotus![Sales Growth % 2 ]
SalesGrowth3 = rsLotus![Sales Growth % 3 ]
PreTaxProfit3 = rsLotus![Pretax Profit 3 ]
PreTaxProfit2 = rsLotus![Pretax Profit 2 ]
PreTaxProfit1 = rsLotus![Pretax Profit 1 ]
PrProfitMarg = rsLotus![Pr#Profit Margin % 1 ]
Week1 = rsLotus![Weeks 1 ]
Week2 = rsLotus![Weeks 2 ]
Week3 = rsLotus![Weeks 3 ]
rsDAO1.AddNew 'Here please add the values from above into the relevant table
rsDAO1![Reg# Number] = RegNumber
rsDAO1![Company Name] = CompanyName
rsDAO1![Sales Growth % 1 ] = SalesGrowth1
rsDAO1![Fixed Assets 1 ] = FixedAssets1
rsDAO1![Period Ending 1 ] = PeriodEnding1
rsDAO1![Total Sales 1] = TotalSales1
rsDAO1![Sales Growth % 2 ] = SalesGrowth2
rsDAO1![Sales Growth % 3 ] = SalesGrowth3
rsDAO1![Pretax Profit 3 ] = PreTaxProfit3
rsDAO1![Pretax Profit 2 ] = PreTaxProfit2
rsDAO1![Pretax Profit 1 ] = PreTaxProfit1
rsDAO1![Pr#Profit Margin % 1 ] = PrProfitMarg
rsDAO1![Weeks 1 ] = Week1
rsDAO1![Weeks 2 ] = Week2
rsDAO1![Weeks 3 ] = Week3
rsDAO1.Update
rsLotus.MoveNext
Loop
rsDAO1.Close
Set rsDAO1 = Nothing
rsLotus.Close
Set rsLotus = Nothing
LotusCn.Close