ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] ¥t¦s³æ¤@¤u§@­¶®É¯à±N³¡¤À¼Ò²Õ¦s¤J

[µo°Ý] ¥t¦s³æ¤@¤u§@­¶®É¯à±N³¡¤À¼Ò²Õ¦s¤J

¦pÃD
²{¦³1­Ó Test.xls ªºÀɮסA¸Ì­±¦³ a¡Bb¡Bc¡Bd ¥|­Ó¤u§@­¶¨Ã¥B¦³ w¡Bx¡By¡Bz ¥|­Ó¼Ò²Õ¥¨¶°

½Ð°Ý¬O§_¯à°÷ ±N a ¤u§@­¶¥t¦s·sÀÉ(.xls)ªº¦P®É±N z ¼Ò²Õ¦s¤J a.xls

·í°õ¦æ a.xls Àɮ׮ɡA¥i¥H¹B¦æ z ¼Ò²Õ¥¨¶°??

½Ð±Ð¦U¦ì«e½ú~¤]ÁÂÁ«e½úÀ°¦£

¦^´_ 1# a703130
¦p VB ¤@¼Ë¡A±N z ¼Ò²Õ¥¨¶°Âà´«¦¨ .dll ¼Ò²Õ¡A
·í°õ¦æ a.xls Àɮ׮ɥç¦P®É±N¦¹ .dll ¶×¤J¨Ã©I¥s z ¼Ò²Õ¥¨¶°¡C

TOP

¦^´_ 2# c_c_lai


©êºp¡A¨S¦³¥Î¹LVB

¤£ª¾¹D¬O§_¯à¦³­Ó½d¨Ò¸Ñ»¡

©Î¬O¦³±Ð¾Ç¤å¥i¥H°Ñ¦Ò??

TOP

¥»©«³Ì«á¥Ñ c_c_lai ©ó 2012-10-24 15:34 ½s¿è

http://club.excelhome.net/thread-353961-1-1.html

TOP

¦^´_ 3# a703130
VBA«Ê¸Ë¬°Dllªº¨Ò¤l¡B¤èªk»PÁ`µ²
»s§@DLL®É¡AThisWorkBook¤¤ªº¥N½X«Ê¸Ë¤èªk¦p¤U¡G
1¡B¥´¶}VB6¡A·s«ØActiveX DLL¡C­×§ï¡u¤uµ{¡v¦WºÙ©M¡uÃþ¼Ò¶ô¡v¦WºÙ¬°»Ý­nªº¦WºÙ¡C¥»¨Ò¤¤¡A¤uµ{­×§ï¬°TestDLL¡AÃþ¼Ò¶ô­×§ï¬°Test¡C
2¡B«Ø¥ß¤Þ¥Î¡C¤@¯ë»Ý­n¤Þ¥ÎMicrosoft Office 11.0 Object Library©MMicrosoft Excel 11.0 Object Library¡C¦pªGVBA¥N½X¤¤ÁÙ¦³¨ä¥L¤Þ¥Î¡A¦bVB¤¤¤]­n¹ï¥L­Ì¤Þ¥Î¡C
3¡B³o¤@¨B´N¬O¨ãÅé«Ê¸Ë¥N½X¤F¡C
¦b­è¤~«Ø¥ß¦nªºTestDLL¤¤¡A±N¥N½X©ñ¤JTestÃþ¼Ò¶ô¤¤¡C
¦p«Ê¸ËThisWorkBook¤¤ªºOpen¨Æ¥ó¡G
Sub wbk_open(EApp As Excel.Application, wb As Excel.Workbook, sh As Excel.Worksheet)
'--VBA¤¤»Ý­n«Ê¸Ëªº¥DÅé¥N½X
End Sub
¨ä¤¤VBA¤¤ªº¥N½X¬°¨Æ¥ý°µ¦nªº­n«Ê¸Ëªº¥N½X¡A¦p¤U­±³o­Ó¨Ò¤l¡G
'¥´¶}¤u§@Á¡«á¦b·í«eªº¤u§@ªíA1¤¤¿é¤JTest
Private Sub workbook_open()
    Cells(1, 1) = "Test"
End Sub
«Ê¸Ë¬°DLLªº¥N½X¬°¡G
Sub wbk_open(EApp As Excel.Application, wb As Excel.Workbook, sh As Excel.Worksheet)
    Cells(1, 1) = "Test"
End sub
²{¦b¦bVB6¤¤¥Í¦¨Dll¡A¨ì¦¹´N§¹¦¨«Ê¸Ë¤F¡C
4¡B¦bVBA¤¤¨Ï¥Î«Ê¸Ëªº¥N½X
­º¥ý¡A¦bVBA¤¤­n¤Þ¥Î­è¤~¥Í¦¨ªºTestDll.dll¡C
µM«á·s«Ø¤@­Ó¼Ò¶ô¡A¦b¨ä¤¤©w¸q³o¼Ë¤@­ÓÅܶqT¡G
Public T As New TestDll.Test
µM«á¦bThisWorkBookªºOpen¤¤¤Þ¥ÎTestDll¤¤ªºTest¡A¥N½X¦p¤U¡G
Private Sub workbook_open()
   On Error Resume Next
   T.wbk_open Application, ThisWorkbook, ActiveSheet
End Sub
³o¼Ë¨C¦¸¥´¶}Excel«á¡A´N¦bSheet1ªºCells(1,1)¤¤¿é¤J¡uTest¡v¡C
·íµM¡A¦pªG§A·Q¦b²Ä2±i¤u§@ªíªºA1¤¤¿é¤JTest¡A¨º»ò¥i¥H³o¼Ë¥Î¡G
Private Sub workbook_open()
   On Error Resume Next
   T.wbk_open Application, ThisWorkbook, Sheets(2)
End Sub

¥H¤W´N¬O¥N½X«Ê¸Ëªº¥þ¹Lµ{¡A»Ý­nª`·Nªº¬OÅܶqªº¶Ç»¼­n¤¬¬Û¹ïÀ³¡C

¤W­±¥Ü¨Ò¤¤ªº«Ê¸Ë¥N½X¬O¥Î3­ÓÅܶq¶Ç»¼ªº¡A¦pªG¥u¥Î1­ÓÅܶq¶Ç»¼¡A¥N½X¦p¤U¡G
'«Ê¸Ë¬°DLLªº¥N½X¬°¡G
Sub wbk_open(sh As Excel.Worksheet)
    Cells(1, 1) = "Test"
End sub
'ThisWorkBook¤¤¨Ï¥ÎDllªº¥N½X¬°
Private Sub workbook_open()
   On Error Resume Next
   T.wbk_open ActiveSheet
End Sub

Dll¤å¥ó©MTest¤å¥ó¡A´ú¸Õ®É½Ð­«·s¤Þ¥ÎTestDll.dll

TOP

¦^´_ 3# a703130
Working_with_Array_Functions_and_DLLs_in_Excel_VBA.pdf (110.8 KB)
Working_with_Array_Functions_and_DLLs_in_Excel_VBA.pdf

TOP

¦^´_ 1# a703130
  1. Sub nn()
  2. ThisWorkbook.VBProject.VBComponents("z").Export "D:\z.bas" '¶×¥X¼Ò²Õ¼È¦s
  3. Sheet1.Copy '¤u§@ªí½Æ»s¨ì·sÀÉ®×
  4. With ActiveWorkbook
  5. .VBProject.VBComponents.Import "D:\z.bas" '¶×¤J¼Ò²Õ
  6. End With
  7. Kill "D:\z.bas" '§R°£¼È¦s¼Ò²Õ
  8. End Sub
½Æ»s¥N½X
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

        ÀR«ä¦Û¦b : ¨Ã«D¦³¿ú¾{¬O§Ö¼Ö¡A°Ý¤ßµL·\¤ß³Ì¦w¡C
ªð¦^¦Cªí ¤W¤@¥DÃD