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

[Âà¶K] ¦p¦ó¤À¿ë¼Ò²Õ¤Î¥þ°ìÅܼƩO¡H

[Âà¶K] ¦p¦ó¤À¿ë¼Ò²Õ¤Î¥þ°ìÅܼƩO¡H

Q:
VBA¦³¤TºØÅܼÆ
°Ï°ì¡B¼Ò²Õ¡B¥þ°ìÅܼƦ@¤TºØ
¤p§Ì¹ï©ó¼Ò²Õ©M¥þ°ìÅܼƤÀ¿ë¤£²M
¤£ª¾­n¦p¦ó°Ï¤À©O¡H

A:
«Å§iÅܼƪº°ò¥»»yªk¦p¤U¡A¤£ª¾­þ¸Ì¤£À´?

Dim variable_name [As variable_type]
¦b¼Ò²Õ¼h¦¸ùØ¥H Dim ©Ò«Å§iªºÅܼơA¸Ó¼Ò²Õ©Ò¦³ªºµ{§Ç¬Ò¥i¨Ï¥Î¡C
¦bµ{§Ç¼h¦¸«Å§iªºÅܼơA«h¥u¥i¦b¸Óµ{§Ç¤¤¨Ï¥Î¡C

Private variable_name [As variable_type]
¦b¼Ò²Õ¼h¦¸¤¤¥Î¨Ó«Å§i¨p¦³ÅܼơA¨Ã°t¸mÀx¦sªÅ¶¡¡C
Private Åܼƥu¾A¥Î©ó«Å§i¥¦­Ìªº¼Ò²Õ¤¤¡C

Public variable_name [As variable_type]
¦b¼Ò²Õ¼h¦¸¤¤¥Î¨Ó«Å§i¤½¥ÎÅܼơA¨Ã°t¸mÀx¦sªÅ¶¡¡C
¨Ï¥Î Public ³¯­z¦¡«Å§iªºÅܼơA¥i¥H¦b©Ò¦³¼Ò²ÕùبϥΠ(°£«D¨Ï¥Î Option Private Module)¡F¦ý·|¨ÏÅܼƥu¦b¥¦­Ì©Ò¦bªº±M®×ùج°¤½¥Îªº¡C
ª`·N Public ³¯­z¦¡µLªk¦bª«¥óÃþ§O¼Ò²Õùثŧi©T©wªø«×ªº¦r¦êÅܼơC


´£¿ô±z¡AÀ´±o¾Ç¥H­P¥Î¤ñ¸û­«­n¡A¤£»Ý©ëªd¦b¦Wµü¤W¡C

Q:
¦pªG§Ú­n«Å§i¤@­Ó¥þ°ìÅܼơA
¤@¶}¾÷³o­ÓÅܼƴN¦s¦b¡A
¨º»ò§Ú­n¦p¦ó«Å§i©O¡H
¥H¤U¬O§Úªº¼gªk¡A¤£ª¾¹D¹ï¤£¹ï
Public s1 As Integer
'³o¬O¦bThisWorkBook¤¤ªºµ{§Ç
Private Sub Workbook_Open()
   s1 = Sheet1.Range("A65535").End(xlUp).Row
End Sub

A:
§A¬O¦bª«¥óÃþ§O¼Ò²ÕThisWorkbook«Å§iÅܼƪº¡A
Sheet1¤]¬Oª«¥óÃþ§O¼Ò²Õ¡C
¦pªGÅܼƭn¦b¤£¦Pªº¼Ò²Õ¤§¶¡¶Ç»¼/Ū¨ú¡A
½Ð¦b¤@¯ë¼Ò²Õ«Å§i¤½¥ÎÅܼơC

¥»©«³Ì«á¥Ñ ryu0417 ©ó 2010-11-17 13:50 ½s¿è

·P®¦~
¤£¦n·N«ä ¦ý«Å§iÅܼƫá, ¬O§_¯à°÷±NÅܼƤº®e¤@¨Ã¼g¤J©O!?

Ex:
¦b¦P¤@­Ó¼Ò²Õ¤º, «Å§imyStr as Str
myStr = "¶W¤H"
·Q¦b¤£¦Psub¨Ï¥ÎmyStr, ¦³¿ìªk°µ¨ì¶Ü!?

TOP

¤@¯ë¼Ò²Õ
Public Const mystr = "¶W¤H"
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¤@¯ë¼Ò²Õ
Public Const mystr = "¶W¤H"
Hsieh µoªí©ó 2010-12-1 00:38



    ½Ð°Ý¤j¤j,³o¼Ë«Å§i ¬O§_·|¦Û°Ê¬°Variant¸ê®Æ«¬ºA????
50 ¦r¸`¥H¤º
¤£¤ä«ù¦Û©w¸q Discuz! ¥N½X

TOP

¥»©«³Ì«á¥Ñ et5323 ©ó 2010-12-1 11:07 ½s¿è

Public Const mystr = "¶W¤H",¥Ñ¤_没¦³对mystrªº数Õu类«¬§@¥X声©ú,mystr¤@©w¬OVariant数Õu类«¬ªº.
¥i¥H显¦¡¦a声©ú:Public Const mystr as string= "¶W¤H",这样mystr´N¬Ostring数Õu类«¬ªº¤F.

TOP

Public Const mystr = "¶W¤H",¥Ñ¤_没¦³对mystrªº数Õu类«¬§@¥X声©ú,mystr¤@©w ...
et5323 µoªí©ó 2010-12-1 11:04

¨º»ò­n«Å§i¨ä¥L ¸ê®Æ«¬ºA­n¦p¦ó¼g?(eg.Integer )
50 ¦r¸`¥H¤º
¤£¤ä«ù¦Û©w¸q Discuz! ¥N½X

TOP

¦^´_ 6# basarasy


    Public Const i As Integer = 100
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¦^´_ 7# Hsieh


    ÁÂÁ¤j¤j,¤S¾Ç²ß¤F.
50 ¦r¸`¥H¤º
¤£¤ä«ù¦Û©w¸q Discuz! ¥N½X

TOP

«Å§i¥þ°ìÅܼƬO«üÅý©Ò¦³¥¨¶°³£¯à¥ÎªºÅܼƪº·N«ä¶Ü

TOP

§Ú«Ü³ßÅw¨Ï¥ÎPublic¡A©Ò¦³ªº¼Ò²Õ¡B¨ç¼Æ³£¥i¥H¨Ï¥Î¡A«Ü¤è«K

°£¦¹¤§¥~¡A³o¼Ë¥i¥H±j¨î¦Û¤v¨Ì·Ó¾A·íªº³W«h¬°¨C¤@­ÓÅܼƩR¤@­Ó¦W¡A

§Y¨Ï¬Oµ{¦¡¤j¤F¡A¤Àªù§OÃþªºÅܼƦWºÙ¤]¤ñ¸û¤£·|·P¨ì²V¶Ã

TOP

        ÀR«ä¦Û¦b : ¤Hªº¤ß¦a¬O¤@²¥¥Ð¡A¤g¦a¨S¦³¼½¤U¦nºØ¤l¡A¤]ªø¤£¥X¦nªºªG¹ê¡C -
ªð¦^¦Cªí ¤W¤@¥DÃD