在VB中如何创建,写入,保存Excel文件。我写入的时候都写到了A列种,怎么才能写到其他列中

解决方案 »

  1.   

    column("B")
    row(2)
    cell(1,1)
      

  2.   

    Dim xlApp As Excel.Application
    Dim xlBook As Excel.Workbook
    Dim xlSheet As Excel.Worksheet
    Set xlApp = CreateObject("Excel.application")
    xlApp.Visible = True
    On Error GoTo ErrorHandler
    xlBook.Close
    ErrorHandler:str = App.Path
    If Right(str, 1) <> "\" Then
    str = str + "\"
    End If
    Set xlBook = xlApp.Workbooks.Open(str & "qitamxb.xls")xlBook.SaveAs (str & "临时文件\其它明细表" & Year(Date) & Format(Month(Date), "0#") & Format(Day(Date), "0#") & Format(Hour(Time), "0#") & Format(Minute(Time), "0#") & Format(Second(Time), "0#") & ".xls")Set xlSheet = xlBook.Worksheets(1)
    'xlsheet.Cells(6, 1) = "i"
    'xlsheet.Cells(1, 1) = biaotou
    xlSheet.Cells(2, 1) = "填表单位:" & Main.Text1.Text
    xlSheet.Cells(2, 7) = "填表日期:" & Date
      

  3.   

    您给我的解答非常有用,再非常感谢您不好意思,再问一下。
    运行您上述的程序,会自动打开Excel,在我要关闭的时候提醒我保存等。
    我在您给我程序的最后我又加上了这么两句:
        xlBook.Save
        xlBook.Close
    另存的文件也能保存关闭,但是还是留下了Excel的程序,如果我要批量生成,保存,关闭文件,这样系统会不会很慢?
    谢谢您的解答·