想要把对应单元格内的内容替换掉,对一个文件夹下的多个excel文件都执行,怎么做?
想把E3和F2两个单元格的内容换成“指定文字”,对同一文件夹下的所有excel文件操作
å½å¶æ¯å®æä¸äºçï¼å¦ä¸å 个代ç é åå ¶ä»å¯å®æã
Dirï¼æ¾å°æ¯ä¸ªæ件
Workbooks.Openï¼æå¼æ件
workbooks(1).cells(1,1)=???, æ¿æ¢åå æ ¼
Saveï¼ä¿å
Workbooks.Closeå ³é
ææ³æE3åF2两个åå
æ ¼çå
容æ¢æâæå®æåâï¼å¯¹åä¸æ件夹ä¸çææexcelæ件
æä½ï¼ä½ ççè¿æ ·è¡åï¼
Sub a()
Dir
Workbooks.Open
Workbooks(1).Cells(E, 3) = æå®æå
Workbooks(1).Cells(F, 2) = æå®æå
Save
Workbooks.Close
End Sub
谢谢
æ¨è¿ä¸ªä¸è¡ï¼å·®çå¤äºã
è¯è¯è¿ä¸ªï¼
Sub a()æ¾ç¤ºâç¼è¯é误ï¼end if没æifåâ
âåæ¢å·æ°ä¸æ示âä¹ç±»çä¸æè¦å é¤åï¼
Sub a()
Dim mydocument
mydocument = Dir("æ件路å¾" & "\*.xls*")
Do While Len(mydocument) > 0 And mydocument ThisWorkbook.Name
'åæ¢å·æ°ä¸æ示
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'æå¼æ件
Workbooks.Open (ThisWorkbook.Path & "\" & mydocument)
Worksheets(1).Cells(3, 5).Value = "æå®å
容"
Worksheets(1).Cells(2, 6).Value = "æå®å
容"
Next
'ä¿å并å
³é
MkDir (ThisWorkbook.Path & "\å·²å®æ")
ActiveWorkbook.SaveAs ThisWorkbook.Path & "\å·²å®æ\" & mydocument
ActiveWorkbook.Close
Save = True
'æ¢å¤å·æ°ä¸æ示
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
ânext没æforâæå äºä¸ä¸ªforååæ¾ç¤ºâ缺å°åéâ
追çSub a()
Dim mydocument
mydocument = Dir("æ件路å¾" & "\*.xls*")
Do While Len(mydocument) > 0 And mydocument ThisWorkbook.Name
'åæ¢å·æ°ä¸æ示
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'æå¼æ件
Workbooks.Open (ThisWorkbook.Path & "\" & mydocument)
Worksheets(1).Cells(3, 5).Value = "æå®å
容"
Worksheets(1).Cells(2, 6).Value = "æå®å
容"
Loop
'ä¿å并å
³é
MkDir (ThisWorkbook.Path & "\å·²å®æ")
ActiveWorkbook.SaveAs ThisWorkbook.Path & "\å·²å®æ\" & mydocument
ActiveWorkbook.Close
Save = True
'æ¢å¤å·æ°ä¸æ示
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
ä¸ç´å¨ç¬¬ä¸ä¸ªæå¼çexcelæ件é循ç¯éªçï¼ä»¥åææ¯æ³ä¿®æ¹åä»æ§ä¿åå¨æºexcelæ件å½ä¸ï¼ä¸å¥½ææï¼è½å¦éº»ç¦æ¨åæ¹ä¸ä¸å¢ï¼å 为æå®å¨æ¯ä¸çªä¸éï¼èä¸ç°å¨ä¹æ¯è¾æ¥ï¼ççé常æè°¢ï¼
追çè¯éªè¿äºï¼å¯ä»¥ä½¿ç¨ã
æ¾ä»£ç çæ件æ°å»ºï¼ä¸è¦å¨æ件路å¾ä¸ã
æ件路å¾ç´æ¥å¤å¶ï¼ä¸è¦å¢å \ã
Sub a()
'åæ¢å·æ°ä¸æ示
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim myFile As String
Dim myDocument As String
myFile = "æ件路å¾"
myDocument = Dir(myFile & "\*.xls*")
Do While Len(myDocument) > 0 And myDocument ThisWorkbook.Name
'æå¼æ件
Workbooks.Open (myFile & "\" & myDocument)
Worksheets(1).Cells(3, 5).Value = "æå®å
容"
Worksheets(1).Cells(2, 6).Value = "æå®å
容"
'ä¿å并å
³é
ActiveWorkbook.Save
ActiveWorkbook.Close
Save = True
myDocument = Dir
Loop
'æ¢å¤å·æ°ä¸æ示
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub