# Re: 当然可以

Posted by David Wong on November 16, 1998 at 09:02:20:

In Reply to: VBA 可以直接被 VB 传叫及应用吗? posted by VBA 新手 on November 14, 1998 at 17:34:25:

你可以看 Que 出的 Using Visual Basic 5，及MS Excel Visual Basic Guide 。

VB 程式简例（其中有些 code 你可以不理）：

Set Excel = CreateObject("Excel.Application")
Set xlBook = Excel.Workbooks.Open(gsStdDatabaseLocal & "\pcb97cht.xls", False, False)

Set xlSheet = xlBook.Worksheets(3)

' Excel.Visible = True
xlSheet.Activate
xlSheet.Columns("A:D").ClearContents
nRow = 0
ssD62.MoveFirst
Do While Not ssD62.EOF
nRow = nRow + 1
xlSheet.Cells(nRow, 1).Value = ssD62!DeptCode
xlSheet.Cells(nRow, 2).Value = ssD62!CCYY
xlSheet.Cells(nRow, 3).Value = ssD62!Amt
ssD62.MoveNext
Loop
Else
MsgBox "No data found"
Set ssD62 = Nothing
Exit Sub
End If
'Passing the parameter list to excel which is used for the macro call
Set xlSheet = xlBook.Worksheets(1)
xlSheet.Activate
xlSheet.Rows("2").ClearContents
xlSheet.Cells(2, 1).Value = "DrawCpare()"
xlSheet.Cells(2, 2).Value = sCompCode
xlSheet.Cells(2, 3).Value = sCompName
xlSheet.Cells(2, 4).Value = sYear
xlSheet.Cells(2, 5).Value = sMonth
xlSheet.Cells(2, 6).Value = mGetUnit(sUnit)
xlSheet.Cells(2, 7).Value = mGetUnitStr(sUnit)
xlSheet.Cells(2, 8).Value = IIf(sAccu, "TRUE", "FALSE")

'Call a Macro Function To Update or Draw the Chart
xlBook.Application.Run ("DrawCpare")
Excel.Application.ScreenUpdating = True
Excel.ActiveWorkbook.Saved = True
Clipboard.Clear
xlBook.activeChart.ChartObjects.Copy
picChart.Picture = Clipboard.GetData()
'Excel.Visible = False
Clipboard.Clear

Follow Ups:

- Re: 当然可以 VBA 新手 20:10:21 11/17/98 (0)