作者ClubT (勇气是实现梦想的魔法)
看板Visual_Basic
标题Re: [VB6 ] 请问用FileSystemObject来处理Excel档案
时间Thu May 7 11:39:47 2009
以前随便写的
请照Command 1,2,3 的顺序看
Private Sub Command1_Click()
Dim xExcel As Object
Dim xbook As Object
Dim xsheet As Object
'Start a new workbook in Excel
Set xExcel = CreateObject("Excel.Application")
Set xbook = xExcel.Workbooks.Add
xbook.worksheets.Add
xbook.worksheets(2).Delete
xbook.worksheets(2).Delete
xbook.worksheets(2).Delete
'Add data to cells of the first worksheet in the new workbook
Set xsheet = xbook.worksheets(1)
xsheet.Name = "aaa"
xsheet.Range("A1").Value = "Last Name"
xsheet.Range("B1").Value = "First Name"
xsheet.Range("A1:B1").Font.Bold = True
xsheet.Range("A2").Value = "Doe"
xsheet.Range("B2").Value = "John"
'Save the Workbook and Quit Excel
xExcel.DisplayAlerts = False '不会跳出询问视窗
xbook.SaveAs "C:\ttt.xls"
xExcel.Quit
MsgBox ("ok")
Set xExcel = Nothing
End Sub
Private Sub Command2_Click()
Dim xExcel As Object, xbook As Object, xsheet As Object
Dim sPath As String
Dim strcmd As String
sPath = "C:\ttt.xls" '自行建立xls的档名
Set xExcel = CreateObject("Excel.Application") '建立excel
Set xbook = xExcel.Workbooks.Open(sPath) 'open工作簿xbook
Set xsheet1 = xbook.worksheets(1) '於xbook工作薄中的第一个表xsheet
Set xsheet2 = xbook.worksheets(2) '於xbook工作薄中的第二个表xsheet
strcmd = "cmd /c copy c:\ttt.xls C:\temp.xls"
Shell strcmd
MsgBox "ok"
xExcel.Visible = False '
xbook.Close (True)
xExcel.Quit
Set xExcel = Nothing
End Sub
Private Sub Command3_Click()
Dim xExcel As Object
Dim xbook As Object
Dim xsheet As Object
Set xExcel = CreateObject("Excel.Application") '建立excel
Set xbook = xExcel.Workbooks.Open("C:\ttt.xls") 'open工作簿xbook
xExcel.Rows("1:1").Select ' 第1列
xExcel.Selection.Copy ' 复制
xExcel.Rows("4:4").Select ' 第4列
xExcel.Selection.PasteSpecial Paste:=-4104, Operation:=-4142, _
SkipBlanks:=False, Transpose:=False
xExcel.Visible = True
End Sub
--
《我的Blog》
http://clubtblog.blogspot.com/
你的资料如下 (这是控制码,每个人都会看到自己的资料)
《ID昵称》 ()
《上站次数》次
《文章篇数》篇
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.134.130.187
※ 编辑: ClubT 来自: 122.116.11.34 (05/18 11:49)