Public Sub PrintExcel(ExcelRec As ADODB.Recordset) Dim i As Integer, j As Integer Dim strSource As String, strDestination As String Dim xlApp As Excel.Application Dim xlBook As Excel.Workbook Dim xlSheet As Excel.Worksheet On Error GoTo Excel_Error strSource = App.Path & "\MDAppl.xls"'模板文件含CHECKBOX控件 strDestination = App.Path & "\MDAppl\" & Applno & ".xls" FileCopy strSource, strDestination Set xlApp = New Excel.Application xlApp.Visible = False Set xlBook = xlApp.Workbooks.Open(strDestination) Set xlSheet = xlBook.Worksheets(1) xlSheet.Cells(38, 1) = "*" & Applno & "*" xlSheet.Cells(38, 12) = Applno xlSheet.Cells(2, 2) = Dept xlSheet.Cells(3, 3) = Cutmno xlSheet.Cells(4, 8) = Comp xlSheet.Cells(5, 8) = Brok xlSheet.Cells(13, 1) = Atth xlSheet.Cells(15, 1) = Reason xlSheet.Cells(18, 10) = Appldte Select Case Ieflag Case "進口" xlSheet.optimp.Value = False xlSheet.optexp.Value = True Case "出口" xlSheet.optimp.Value = True xlSheet.optexp.Value = False End Select If Not ExcelRec.EOF And Not ExcelRec.BOF Then ExcelRec.MoveFirst i = 1 Do While Not ExcelRec.EOF xlSheet.Cells(i + 7, 1) = ExcelRec.Fields(0) xlSheet.Cells(i + 7, 3) = ExcelRec.Fields(1) xlSheet.Cells(i + 7, 6) = ExcelRec.Fields(2) xlSheet.Cells(i + 7, 9) = ExcelRec.Fields(3) ExcelRec.MoveNext i = i + 1 Loop End If Set ExcelRec = Nothing xlApp.Visible = True xlBook.PrintPreview xlApp.Visible = False xlBook.Save xlApp.Quit Set xlApp = Nothing Set xlBook = Nothing Set xlSheet = Nothing Exit Sub Excel_Error: Set xlApp = Nothing Set xlBook = Nothing Set xlSheet = Nothing MsgBox Err.Description End Sub 此為我掉用的原碼但運行時報錯(Method or data member not found) 其中optimp,optexp為CHECKBOX控件 ,請幫忙修改.
Dim i As Integer, j As Integer
Dim strSource As String, strDestination As String
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
On Error GoTo Excel_Error
strSource = App.Path & "\MDAppl.xls"'模板文件含CHECKBOX控件
strDestination = App.Path & "\MDAppl\" & Applno & ".xls"
FileCopy strSource, strDestination
Set xlApp = New Excel.Application
xlApp.Visible = False
Set xlBook = xlApp.Workbooks.Open(strDestination)
Set xlSheet = xlBook.Worksheets(1)
xlSheet.Cells(38, 1) = "*" & Applno & "*"
xlSheet.Cells(38, 12) = Applno
xlSheet.Cells(2, 2) = Dept
xlSheet.Cells(3, 3) = Cutmno
xlSheet.Cells(4, 8) = Comp
xlSheet.Cells(5, 8) = Brok
xlSheet.Cells(13, 1) = Atth
xlSheet.Cells(15, 1) = Reason
xlSheet.Cells(18, 10) = Appldte
Select Case Ieflag
Case "進口"
xlSheet.optimp.Value = False
xlSheet.optexp.Value = True
Case "出口"
xlSheet.optimp.Value = True
xlSheet.optexp.Value = False
End Select
If Not ExcelRec.EOF And Not ExcelRec.BOF Then
ExcelRec.MoveFirst
i = 1
Do While Not ExcelRec.EOF
xlSheet.Cells(i + 7, 1) = ExcelRec.Fields(0)
xlSheet.Cells(i + 7, 3) = ExcelRec.Fields(1)
xlSheet.Cells(i + 7, 6) = ExcelRec.Fields(2)
xlSheet.Cells(i + 7, 9) = ExcelRec.Fields(3)
ExcelRec.MoveNext
i = i + 1
Loop
End If
Set ExcelRec = Nothing
xlApp.Visible = True
xlBook.PrintPreview
xlApp.Visible = False
xlBook.Save
xlApp.Quit
Set xlApp = Nothing
Set xlBook = Nothing
Set xlSheet = Nothing
Exit Sub
Excel_Error:
Set xlApp = Nothing
Set xlBook = Nothing
Set xlSheet = Nothing
MsgBox Err.Description
End Sub
此為我掉用的原碼但運行時報錯(Method or data member not found) 其中optimp,optexp為CHECKBOX控件 ,請幫忙修改.