Dim DLG As New OpenFileDialog, FileName As String '定义变量,对话框,文件路径
DLG.Title = "请选择要写入的Excel文件" '对话框标题
DLG.Filter = "Excel文件(*.xls*)|*.xls*" '对话框文件筛选器
If DLG.ShowDialog = Windows.Forms.DialogResult.OK Then FileName = DLG.FileName '选择文件
If FileName = "" Then Return Nothing
Dim XlApp As Object = CreateObject("Excel.Application") '创建Excel对象
XlApp.Visible = True '并显示出来
Dim XlWb As Object = XlApp.Workbooks.Open(FileName) '打开工作簿文件
Dim Rng As Object = XlApp.InputBox("请选择要写入的单元格", "选择单元格", Type:=8)
If Rng Is Nothing Then Return Nothing
Dim InputStr As String = XlApp.InputBox("请输入要写入选择单元格的内容", "输入内容")
If InputStr = "" Then Return Nothing '选择单元格写入内容
Rng.Value = InputStr '写入内容
[此贴子已经被作者于2012-1-24 19:39:43编辑过]