看板 Visual_Basic 關於我們 聯絡資訊
以前隨便寫的 請照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)