Quit Excel session
กระทู้เก่าบอร์ด อ.สุภาพ ไชยา

 233   1
URL.หัวข้อ / URL
Quit Excel session

ถามไว้ที่ http://www.utteraccess.com/forums/showflat.php?Cat=&Board=access_97&Number=159701&page=0&view=collapsed&sb=5&o=7&fpart=1 
 
เขาต้องการที่จะส่งค่าจาก Access ไปคำนวณใน Excel แล้วนำค่าที่ได้กลับมายัง Access 
 
ผมแนะนำให้เขาเรียกใช้ฟังก์ชันของ Excel ใน Access เลยก็ได้ จะไม่ต้องส่งข้อมูลกลับไปกลับมา 
 
นี่คือตัวอย่างการเรียกใช้ฟังก์ชัน Ceiling() ของ Excel Worksheet Function ใน Access. 
 
Function CeilingExcel(Num As Double, Sig As Double) As Double 
    Dim xlApp As Object 
    Set xlApp = CreateObject("Excel.Application") 
    CeilingExcel = xlApp.WorksheetFunction.Ceiling(Num, Sig) 
End Function 
 
ลองใช้งานดู จะได้ 
 
? CeilingExcel(1.45,2) 
 2  
 
 
หรือถ้ายังยืนยันที่จะส่งข้อมูลแบไปกลับ ก็ให้ลองโค้ดต่อไปนี้ดูครับ 
 
Sub GetValueFromExcelCell() 
Dim ObjExcel As Object 
Dim MySheet As Object, Sheet As Object 
 
' Open Excel and open a file book1.xls located in C:. 
Set ObjExcel = CreateObject("Excel.Application") 
Set MySheet = ObjExcel.workbooks.Open("C:\book1.xls").Sheets(1) 
 
' Make Excel visible. 
ObjExcel.Visible = True 
 
' Type in figure in A1 and B1 Cells. 
MySheet.Cells(1, 1).Value = 15 
MySheet.Cells(1, 2).Value = 700 
 
' Return a value from C3 cell. 
' I put =SUM(A1:B1) formula in this cell. 
' So you should see 715 in this message box. 
MsgBox MySheet.Cells(1, 3).Value 
 
' Save the workbook and close Excel. 
ObjExcel.ActiveWorkbook.Save 
ObjExcel.ActiveWorkbook.Close 
Set MySheet = Nothing 
ObjExcel.Quit 
Set ObjExcel = Nothing 
End Sub 

1 Reply in this Topic. Dispaly 1 pages and you are on page number 1

1 @R06670
   
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.0824s