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

[Âà¶K] ½Ð°ÝVBA©óEXCEL·s¼W¤å¦rÀÉ®×+¤é´Á

[Âà¶K] ½Ð°ÝVBA©óEXCEL·s¼W¤å¦rÀÉ®×+¤é´Á

¦U¦ì«e½ú¦­¦w
«á¾Ç¦³·s¦P¾Çµo°Ý,½Ð¦U¦ì«e½ú«ü¾É!ÁÂÁÂ

¦U¦ì¤j¤j¦n
½Ð°ÝVBA©óEXCEL 2019¼g¥X·s¼W¤å¦rÀÉ®×+¤é´Áªº«ö¶s¡A¤ñ¦p¤µ¤Ñ¤é´Á¬O2022/11/19¡A³]­p¤@­Ó«ö¶s¡A©ó¥Ø«eEXCELÀɮשҦbªºÀɮק¨¸Ì­±²£¥Í¤@­Ó20221119.TXT,
­n«ç¼Ë°µ¡AÁÂÁÂ

¥»©«³Ì«á¥Ñ Andy2483 ©ó 2022-11-22 08:36 ½s¿è

¦^´_ 4# ­ã´£³¡ªL

ÁÂÁ«e½ú«ü¾É
ÁÂÁ½׾Â
Option Explicit
Sub CreateObject_Scripting_FileSystemObject_AND_OpenTextFile()
Dim fs, a
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile(ThisWorkbook.Path & "\" & Format(Date, "yyyymmdd") & ".txt", True)
a.WriteLine ("This is a test.")
a.Close
'https://learn.microsoft.com/zh-tw/office/vba/language/reference/user-interface-help/filesystemobject-object
End Sub
Sub CreateObject_ADODB_Stream()
'https://club.excelhome.net/thread-868093-1-1.html
End Sub

µ½¥Î»¡©ú:

TOP

¦^´_ 3# ­ã´£³¡ªL


    ÁÂÁ«e½ú«ü¾É
¾÷·|±Ð¨|¬O³Ì¨Îªº¾Ç²ß¾÷·|
¤Z¨«¹L¥²¯d¤U²ª¸ñ
Append-¼g¦bÀɮתº§ÀºÝ...²Ö¼Wµ²ªG:


Option Explicit
Sub ²£¥Í¤å¦rÀÉ_Append_¼g¦bÀɮתº§ÀºÝ_²Ö¼W()
Dim xT$, xFile$
xT = "Åwªï¤@°_¨Ó¾Ç²ß!½×¾Â¨ä¹ê¨S¤°»òªùÂe!¼ç³W«h´N¬Oµê¤ß¾Ç²ß!"
xFile = ThisWorkbook.Path & "\" & Format(Date, "yyyymmdd") & ".txt"
Open xFile For Append As #1 'Append-¼g¦bÀɮתº§ÀºÝ...²Ö¼W
'https://learn.microsoft.com/zh-tw/office/vba/language/reference/user-interface-help/open-statement
Print #1, xT
Close #1
End Sub

TOP

¥»©«³Ì«á¥Ñ Andy2483 ©ó 2022-11-22 07:46 ½s¿è

¦^´_ 2# ­ã´£³¡ªL


    ÁÂÁ«e½ú«ü¾É
¾Ç²ß¤ß±o¦p¤U,½Ð«e½ú¦A«ü¥¿«ü¾É!

²£¥ÍÀÉ®×:


¶}±ÒÀÉ®×À˵ø¤º®e:


Option Explicit
'¡ô­n¨DÅܼƫŧi
Sub ²£¥Í¤å¦rÀÉ_OutputÂл\¸ê®Æ()
Dim xT$, xFile$
'¡ô«Å§iÅܼÆ:xT$ = xT As String(¦r¦ê)
'https://learn.microsoft.com/zh-tw/dotnet/visual-basic/language-reference/statements/dim-statement

xT = "¤å¦rÀɤº®e"
'¡ô¥OxT ¬O·Q­n¿é¤J¦b¤å¦rÀɤ¤ªº¤å¦r¦r¦ê
xFile = ThisWorkbook.Path & "\" & Format(Date, "yyyymmdd") & ".txt"
'¡ô¥OxFile ¬O¬¡­¶Ã¯ªº§¹¾ã¸ô®|»PÀɦW°ÆÀɦWªº¦r¦ê
'ThisWorkbook.Path:
'https://learn.microsoft.com/zh-tw/office/vba/api/excel.workbook.path
'Format():
'https://learn.microsoft.com/zh-tw/office/vba/language/reference/user-interface-help/format-function-visual-basic-for-applications

Open xFile For Output As #1 'OutputÂл\¸ê®Æ
'¡ôOpen ³¯­z¦¡:
'https://learn.microsoft.com/zh-tw/office/vba/language/reference/user-interface-help/open-statement

Print #1, xT
'¡ôPrint # ³¯­z¦¡
'https://learn.microsoft.com/zh-tw/office/vba/language/reference/user-interface-help/printstatement

Close #1
End Sub

TOP

¥t¥~, ¥i·j¤U­±¨âºØ¤èªk//
CreateObject("Scripting.FileSystemObject") + OpenTextFile
CreateObject("ADODB.Stream")

TOP

Sub ²£¥Í¤å¦rÀÉ_2()
xT = "¤å¦rÀɤº®e"
xFile = thisworkbook.path & "\" & format(date,"yyyymmdd") & ".txt"
Open xFile For Append As #1  'Append-¼g¦bÀɮתº§ÀºÝ...²Ö¼W
Print #1, xT
Close #1
End Sub

TOP

Sub ²£¥Í¤å¦rÀÉ()
xT = "¤å¦rÀɤº®e"
xFile = thisworkbook.path & "\" & format(date,"yyyymmdd") & ".txt"
Open xFile For Output As #1  'OutputÂл\¸ê®Æ
Print #1, xT
Close #1
End Sub

TOP

        ÀR«ä¦Û¦b : ·O´d¨S¦³¼Ä¤H¡A´¼¼z¤£°_·Ð´o¡C
ªð¦^¦Cªí ¤W¤@¥DÃD