vba让用户从ms访问工作表中select一个范围

下面的子RangeSelectionPrompt让用户select一个单元格范围。 下面的代码仅适用于此代码在Excel文件上。

我想知道在MSAccess中执行此代码。 我想捕捉用户select的范围并进行数据操作。 是可能的还是我抽烟了很多。

从Access我知道如何午餐的Excel,检测有多lessWBK打开,浏览工作簿,….表格Excel我知道如何创build一个加载项,连接到数据库,并在用户select后传输数据,但这不是我想要的。

Sub RangeSelectionPrompt() Dim rng As Range Set rng = Application.InputBox("Select a range", "Obtain Range Object", Type:=8) MsgBox "The cells selected were " & rng.Address End Sub 

问题解决了

 Option Compare Database Option Explicit Dim xlApp As Excel.Application Dim xlWB As Excel.Workbook Dim rng As Range Sub GetUserSelection() On Error GoTo ErrExcelinstance Set xlApp = GetObject(, "Excel.Application") Set xlWB = xlApp.ActiveWorkbook ' the bug was Set xlWB = xlApp.ActiveWorkbook.ActiveSheet.Select RangeSelectionPrompt Exit Sub ErrExcelinstance: Select Case Err.Number Case 429 Err.Clear MsgBox "No Workbook Open" Set xlApp = Nothing Set xlWB = Nothing Case Else Set xlApp = Nothing Set xlWB = Nothing MsgBox Err.Number & " " & Err.Description Err.Clear End Select End Sub Sub RangeSelectionPrompt() On Error GoTo RangeSelectionPrompterr: Set rng = xlApp.InputBox("Select a range", "Obtain Range Object", Type:=8) MsgBox "The cells selected were " & rng.Address Exit Sub RangeSelectionPrompterr: Select Case Err.Number Case 424 Err.Clear MsgBox "User did not perform selection" Set xlApp = Nothing Set xlWB = Nothing Case Else Set rng = Nothing MsgBox Err.Number & " " & Err.Description Err.Clear End Select End Sub