|
楼主 |
发表于 2022-12-25 20:56
|
显示全部楼层
请教老师,为了让用户自己进行选择数据源表,我将您的代码结合其他老师的文件选择结合在一起,但是总是提示:至少一个参数没有被指定值,麻烦老师帮忙看看,该如何改正使之正常运行。
Sub limonet()
Dim f$
'f = ThisWorkbook.Path & Application.PathSeparator & "1.xlsx" '指定工作簿
With Application.FileDialog(msoFileDialogOpen) '选择工作簿
.InitialFileName = ThisWorkbook.Path
.Title = "请选择对应的数据源文件" '如无此句亦可,默认显示“打开文件”
With .Filters
.Clear
.Add "Excel文件(xls*)", "*.xls*"
End With
.AllowMultiSelect = False
If .Show Then f = .SelectedItems(1) Else Exit Sub
End With
Dim Cn As Object, StrSQL$
Set Cn = CreateObject("adodb.connection")
' Cn.Open "provider=microsoft.ace.oledb.12.0;extended properties=excel 12.0;data source=" & ThisWorkbook.Path & "\2.xlsx"
StrSQL = "select 商品名称Xin,商品规格Xin,生产企业Xin,批准文号Xin from [Sheet1$A2:H]a right JOIN [excel 12.0;database=" _
& ThisWorkbook.FullName & "].[Sheet1$F3:j]b on b.商品编号NEW=a.商品编号Xin"
Range("G4").CopyFromRecordset Cn.Execute(StrSQL)
End Sub
谢谢! |
|