-------第一次匯出的時候沒問題,再匯出第二次的時候提示“物件range的方法_worksheet失敗”
----------代碼中的mf1為mshflexgrid控制元件---------------------
Private Sub Command1_Click()
Dim TempExcel As Excel.Application
Dim TempSheet As Excel.Worksheet
Dim intI As Integer
Dim intJ As Integer
If mf1.Rows > 1 Then
Set TempExcel = New Excel.Application
TempExcel.Application.Visible = True
TempExcel.Workbooks.Add (1)
Set TempSheet = TempExcel.ActiveWorkbook.ActiveSheet
With TempExcel.ActiveCell.Characters(Start:=1, Length:=26).Font
.Name = "宋體"
.FontStyle = "加粗"
.Size = 18
'.Height = 22
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = True
'.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
For intI = 0 To mf1.Rows - 1
For intJ = 0 To mf1.Cols - 1
TempSheet.Cells(intI + 4, intJ + 1) = mf1.TextMatrix(intI, intJ)
Next intJ
Next intI
TempSheet.Application.DisplayAlerts = False '匯出后的錯誤不提示
TempSheet.Cells(1, 1) = Label1.Caption & Label2.Caption
TempSheet.Range("A1:P1").MergeCells = True
TempSheet.Range("A1:A1").HorizontalAlignment = xlCenter
TempSheet.Cells(2, 1) = Label3.Caption & Combo2.Text & Space(15) & Label5.Caption & Label4.Caption & Space(15) & Label6.Caption & Label7.Caption & Space(15) & Label8.Caption & Label9.Caption & Space(15) & Label10.Caption & Label11.Caption
TempSheet.Range("A2:P2").MergeCells = True
TempSheet.Range("A2:A2").HorizontalAlignment = xlCenter
TempSheet.Range("A4:A6").MergeCells = True
TempSheet.Range("I4:I6").MergeCells = True
TempSheet.Range("J4:J6").MergeCells = True
TempSheet.Range("K4:K6").MergeCells = True
TempSheet.Range("L4:L6").MergeCells = True
TempSheet.Range("M4:M6").MergeCells = True
TempSheet.Range("N4:N6").MergeCells = True
TempSheet.Range("O4:O6").MergeCells = True
TempSheet.Range("P4:P6").MergeCells = True
TempSheet.Columns("A:N").AutoFit
TempSheet.Range("A:P").HorizontalAlignment = xlCenter
TempSheet.Range(Cells(4, 1), Cells(mf1.Rows + 3, 16)).Borders.LineStyle = xlContinuous
TempSheet.Cells(mf1.Rows + 6, 1) = Text2.Text
Else
MsgBox "沒有可匯出的資料", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
End Sub
uj5u.com熱心網友回復:
有人知道嗎?自己頂一下。uj5u.com熱心網友回復:
另存為.csv格式?uj5u.com熱心網友回復:
第二次匯出就報錯了,沒做保存。uj5u.com熱心網友回復:
of 123 大神,幫我解決下吧~~~~~help轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/130487.html
標籤:控件
