A. 濡備綍鎵歸噺淇鏀瑰氫釜excel鏂囦歡鍐呭癸紵
瑕佹壒閲忎慨鏀瑰氫釜 Excel 鏂囦歡鍐呭癸紝浣犲彲浠ヤ嬌鐢 Excel 鐨 VBA錛圴isual Basic for Applications錛夊畯鏉ュ疄鐜般備互涓嬫槸涓涓紺轟緥浠g爜錛屽彲浠ュ府鍔╀綘瀹屾垚榪欎釜浠誨姟錛
鎵撳紑 Excel錛屽苟鎵撳紑浣犺佹壒閲忎慨鏀圭殑鏂囦歡澶廣
鍦 Excel 涓鎵撳紑 VBA 緙栬緫鍣ㄣ備綘鍙浠ラ氳繃鎸変笅Alt + F11蹇鎹烽敭鏉ユ墦寮瀹冦
鍦 VBA 緙栬緫鍣ㄤ腑錛岄夋嫨 "鎻掑叆" 鑿滃崟錛岀劧鍚庨夋嫨 "妯″潡"銆
鍦ㄦ柊鍒涘緩鐨勬ā鍧椾腑錛屽嶅埗騫剁矘璐翠互涓嬩唬鐮侊細
vba澶嶅埗浠g爜
Sub鎵歸噺淇鏀笶xcel鏂囦歡()
Dim MyFolder As String
Dim MyFile As String
Dim MyWorkbook As Workbook
' 璁劇疆鏂囦歡澶硅礬寰
MyFolder = "C:璺寰刓鍒癨浣犵殑鏂囦歡澶筡"
' 閬嶅巻鏂囦歡澶逛腑鐨勬墍鏈 Excel 鏂囦歡
MyFile = Dir(MyFolder & "*.xlsx", vbNormal)
Do While MyFile <> ""
' 鎵撳紑 Excel 鏂囦歡
Set MyWorkbook = Workbooks.Open(MyFolder & MyFile)
' 淇鏀規枃浠跺唴瀹癸紝榪欓噷浠ヤ慨鏀圭涓鍒楀唴瀹逛負渚
MyWorkbook.Sheets(1).Range("A1").Value = "鏂扮殑鍐呭"
' 淇濆瓨騫跺叧闂 Excel 鏂囦歡
MyWorkbook.Save
MyWorkbook.Close
' 鑾峰彇涓嬩竴涓 Excel 鏂囦歡
MyFile = Dir
Loop
End Sub
灝"C:璺寰刓鍒癨浣犵殑鏂囦歡澶筡"鏇挎崲涓哄疄闄呯殑鏂囦歡澶硅礬寰勩
灝嗕唬鐮佷腑鐨"鏂扮殑鍐呭"鏇挎崲涓轟綘鎯寵佷慨鏀圭殑鍐呭廣
鎸変笅F5閿鎴栭夋嫨 "榪愯" -> "榪愯屽瓙渚嬬▼" 鏉ヨ繍琛屽畯銆
榪愯屽悗錛岃ヤ唬鐮佸皢閬嶅巻鎸囧畾鏂囦歡澶逛腑鐨勬墍鏈 Excel 鏂囦歡錛屽苟淇鏀規瘡涓鏂囦歡涓絎涓鍒楃殑鍐呭廣傝風『淇濆湪榪愯屽畯涔嬪墠澶囦喚浣犵殑鏂囦歡錛屼互闃叉剰澶栧彂鐢熴