网上查到的这个可以但是,只写入到类模块,我希望能写到Thisworkbook中或Sheet2...中
oXL = Createobject("Excel.Application")
*!* oXL.Visible = .t.
oBook=oXL.Workbooks.Add()
oSheet = oBook.Sheets(1)
Text to cc Noshow Pretext 1+2 Public Sub DoKbTest(oSheetToFill As Object) Dim i As Integer, j As Integer Dim sMsg As String For i = 1 To 10 For j = 1 To 2 sMsg = Str(i) & "," & Str(j) oSheetToFill.Cells(i, j).Value = sMsg Next j Next i End Sub
EndText
Try oVBE = oXL.VBE.ActiveVBProject oErr = Null
Catch To oErr
Endtry
If !Isnull(oErr) And oErr.ErrorNo == 1943 Text to cMsg Noshow Pretext 1+2 当前的 Excel 配置不允许执行这个宏,请检查 Excel 配置。 请确认勾选了: 可靠发行商中的 “信任对 Visual Basic 项目”的访问 EndText Messagebox(cMsg, 0, '') oXL.Visible = .T. (1).Controls(6).Controls(14).Controls(3).Execute()
Endif
Try om = oXL.VBE.ActiveVBProject.VBComponents.Add(1) om.CodeModule.AddFromString(cc) oXL.Run("DoKbTest", oSheet) oXL.Visible = .T.
Catch To oErr Messagebox(oErr.Message + 0h0d0a0d0a + '你没有正确设置安全选项。', 0, '') oXL.Quit oXL = Null
Endtry