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 鏂囦欢锛屽苟淇鏀规瘡涓鏂囦欢涓绗涓鍒楃殑鍐呭广傝风‘淇濆湪杩愯屽畯涔嬪墠澶囦唤浣犵殑鏂囦欢锛屼互闃叉剰澶栧彂鐢熴