在網路上查了很多資料 但偏偏都少了這一句

請先 引用 Micorsoft Excel 11.0 Object Libary
讓我 try 了好久 >_ 0 Then
Err.Clear
Set ExcelApp = CreateObject("Excel.application")
End If
Dim wsBook As Workbook
Dim wsSheet As Worksheet
With ExcelApp.AutoCorrect.Application
.WindowState = xlMinimized
.SheetsInNewWorkbook = 1
.Visible = False
.Workbooks.Add
Set wsBook = .ActiveWorkbook
Set wsSheet = .ActiveSheet
End With

proBar.Min = 0
proBar.Max = myGrid.Rows
proBar.Value = 0
proBar.Visible = True

With wsSheet
.Cells.Font.Name = "System"
.Cells.Font.Size = 12
.Name = "Page1"

Range(Cells(1, 1), Cells(1, myGrid.Cols)).Select
Selection.HorizontalAlignment = xlCenter
Selection.VerticalAlignment = xlCenter
Selection.Merge '合併表格
'.Cells(1, 1) = strHeader

Range(Cells(2, 1), Cells(2, myGrid.Cols)).Select
Selection.HorizontalAlignment = xlCenter
Selection.VerticalAlignment = xlCenter
Selection.Merge '合併表格
'.Cells(2, 1) = strInfo

'開始複製到 Excel
For r = 0 To myGrid.Rows - 1
For c = 0 To myGrid.Cols - 1
.Cells(r + 3, c + 1) = myGrid.TextMatrix(r, c)
Next
On Error Resume Next
proBar.Value = r + 1
If Err.Number 0 Then Err.Clear
Next


Range(.Cells(3, 1), .Cells(myGrid.Rows + 2, myGrid.Cols)).Select

With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlWide
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlWide
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlWide
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlWide
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End With

proBar.Visible = False

ExcelApp.AutoCorrect.Application.DisplayAlerts = True
Call ExcelApp.AutoCorrect.Application.ActiveWorkbook.SaveAs(strFileName)
ExcelApp.Quit
End Sub







Private Sub Form_Load()
'*********************
'*將 Northwind.sdf 轉入 MSHfixgrid
'*************************
Dim sqlfile As String
Dim con As New ADODB.Connection

sqlfile = App.Path & "\northwind.sdf"

With con
.Provider = "Microsoft.SQLSERVER.CE.OLEDB.3.5"
.Open sqlfile
End With

Adodc1.ConnectionString = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=" & App.Path & "\northwind.sdf"
Adodc1.RecordSource = "select * from employees"
Adodc1.Refresh
Set MSH.DataSource = Adodc1



End Sub

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 Rh 的頭像
    Rh

    程式狂想曲

    Rh 發表在 痞客邦 留言(0) 人氣()