有excel表      A          B       C       D     E     F
 1   账号       姓名    金额 2  3024578      fhj    650 3  3058971     kkj     750 4   308922      ghj    900 ..   ....      ..      ...  用VB操作将金额这一列数字每个都减10,并保存为文本,如何实现????

解决方案 »

  1.   


    '使用ADO获取Excel数据,接下保存为文件就简单了!
    '下面给你附上使用ADO打开Excel文件的代码
    dim sCmd as String        
    Set m_rdsData = New ADODB.Recordset
    'm_rdsData.CursorLocation = adUseClient
    'm_rdsData.CursorType = adOpenStaticsql = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";
    sql = sql + "文件名"
    sql = sql + ";Extended Properties=""EXCEL 8.0;HDR=YES;IMEX=1"";"m_rdsData.Open "[sheet1$]", sql
    '至此打开Excel表
    '接下的工作自己查VB帮助文档吧!眼困要睡了!
      

  2.   

      '在工程中引用 Microsoft office 11.0 Object
      Public ex   As Excel.Application
      Public wb   As Excel.Workbook
      Public sh   As Excel.Worksheet
      Private Sub Command3_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")
        'Set wb = ex.Workbooks.Add '新建excel
        Set wb = ex.Workbooks.Open("c:\A.xls")  ' 你的A文件
        Set sh = wb.Sheets(1)   '第一个工作表
        
         Count = ex.Application.WorksheetFunction.CountA(Columns("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
       
         'ex.Visible = True
        Set ex = Nothing
        Set wb = Nothing
        Set sh = Nothing
    End Sub