Private Sub Command1_Click()'打开EXCEL文件 取出A列到数组 ' 设置“CancelError”为 TrueCommonDialog1.CancelError = TrueOn Error GoTo ErrHandler ' 设置标志 CommonDialog1.Flags = cdlOFNHideReadOnly ' 设置过滤器 CommonDialog1.Filter = "Microsoft Excel Files (*.xls)|*.xls" ' 指定缺省的过滤器 CommonDialog1.FilterIndex = 2 ' 显示“打开”对话框 CommonDialog1.ShowOpen ' 显示选定文件的名字 Dim SQL As String Dim Ex As New Excel.Application Dim ExW As Excel.Workbook Dim Exs As Excel.Worksheet Dim Result Dim Row_l Dim i As Integer '打开EXCEL文件 On Error GoTo 0 Set Ex = CreateObject("Excel.Application") Set ExW = Ex.Workbooks.Open(CommonDialog1.FileName) Set Exs = ExW.Worksheets("sheet1") Exs.Columns("A:A").Select Exs.Copy Result = Clipboard.GetText Row_l = Split(Result, vbCrLf)ExW.Close '关闭工作簿 Set Exs = Nothing '释放对象,下同 Set ExW = Nothing Set Ex = NothingFor i = 0 To UBound(Row_l) Debug.Print Row_l(i) Next ErrHandler: End Sub
Result = Clipboard.GetText 这句编译不过,这里的Clipboard是个什么对象
Private Sub Command1_Click()'打开EXCEL文件 取出A列到数组
' 设置“CancelError”为 TrueCommonDialog1.CancelError = TrueOn Error GoTo ErrHandler
' 设置标志
CommonDialog1.Flags = cdlOFNHideReadOnly
' 设置过滤器
CommonDialog1.Filter = "Microsoft Excel Files (*.xls)|*.xls"
' 指定缺省的过滤器
CommonDialog1.FilterIndex = 2
' 显示“打开”对话框
CommonDialog1.ShowOpen
' 显示选定文件的名字
Dim SQL As String
Dim Ex As New Excel.Application
Dim ExW As Excel.Workbook
Dim Exs As Excel.Worksheet
Dim Result
Dim Row_l
Dim i As Integer
'打开EXCEL文件
On Error GoTo 0
Set Ex = CreateObject("Excel.Application")
Set ExW = Ex.Workbooks.Open(CommonDialog1.FileName)
Set Exs = ExW.Worksheets("sheet1")
Exs.Columns("A:A").Select
Exs.Copy
Result = Clipboard.GetText
Row_l = Split(Result, vbCrLf)ExW.Close '关闭工作簿
Set Exs = Nothing '释放对象,下同
Set ExW = Nothing
Set Ex = NothingFor i = 0 To UBound(Row_l)
Debug.Print Row_l(i)
Next
ErrHandler:
End Sub
这句编译不过,这里的Clipboard是个什么对象
如果通过不了 哪是你其他代码的问题 我的代码http://clubfiles3.liba.com/2008/08/25/11/16146551.rar
要做到这些,必须要引用EXCEL对象,并操作CLIPBOARD对象