本帖最后由 chinesetyq 于 2009-06-27 01:21:06 编辑

解决方案 »

  1.   

    Public ex  As Object
    Public wb  As Object
    Public sh  As Object
    注意你是在 VB 中,不是在 Excel/VBA 中。这一句也要改一下:
    'Count = ex.Application.WorksheetFunction.CountA(Columns("C:C"))
    Count = ex.Application.WorksheetFunction.CountA("C:C")
    其它的问题你自己解决,没什么难度。
      

  2.   

    按照Chen8013的意思改为  Public ex  As Object
    Public wb  As Object
    Public sh  As ObjectPrivate Sub Command1_Click()
     Dim i As Long, A As Long
      Dim arr() As String, str As String, Count As Long
      Dim Result As String
        Set ex = CreateObject("Excel.Application")  ------这出现"ActiveX不能创建对象"的错误提示, 如何修改??????????
        
        Set wb = ex.Workbooks.Open("c:\test.xls")  
        Set sh = wb.Sheets(1)  
        
        Count = ex.Application.WorksheetFunction.CountA("C:C")
          For i = 1 To Count
            If sh.Cells(i + 1, 3) <> "" Then
            Result = Result & Val(sh.Cells(i + 1, 3) - 10) & vbCrLf
            End If
          Next i
        Open "c:\Result.txt" For Output As #1        Print #1, Result
        Close #1
        MsgBox "数据保存在" & "c:\result.txt 中"
        wb.Close SaveChanges:=True        ex.Quit
      
            Set ex = Nothing
        Set wb = Nothing
        Set sh = NothingEnd Sub
      

  3.   

    楼主的office版本不是2003版吧,2003版没有这个问题,如果是2000版,引用 Microsoft office 9.0 Object 
      

  4.   

     我引用的是excel 11.0  还有我只想让金额这一列的数字都减少10元,
    这样改行吗? 
    For i = 1 To Count 
          If sh.Cells(i + 1, 3) <> "" Then 
            sh.Cells(i,3)= sh.Cells(i + 1, 3) - 10) 
            End If 
          Next i 
      

  5.   

    在你原始代码上更改:
    1. Set ex = CreateObject("Excel.Application") 改为 Set ex =  new excel.application
    2.减10元这样更改合适一点
        For i = 1 To Count 
          If sh.Cells(i + 1, 3) <> "" Then 
            sh.Cells(i,3)= val(sh.Cells(i + 1, 3)) - 10 
          End If 
        Next i 
      

  6.   

       孤独剑给的sh.Cells(i,3)= val(sh.Cells(i + 1, 3)) - 10