[¸Ñ¨M¤F¡A§ï¬°¤À¨É] ¥ÎVBA§å¦¸À°¨ä¥Lexcel ªºVB±M®×³]©w±K½XÂê©w
- ©«¤l
- 79
- ¥DÃD
- 2
- ºëµØ
- 0
- ¿n¤À
- 193
- ÂI¦W
- 0
- §@·~¨t²Î
- Winwos 7 64 bits
- ³nÅ骩¥»
- Excel 2003/2007
- ¾\ŪÅv
- 20
- ©Ê§O
- ¨k
- ¨Ó¦Û
- TAIPEI
- µù¥U®É¶¡
- 2010-8-25
- ³Ì«áµn¿ý
- 2019-9-20
|
[¸Ñ¨M¤F¡A§ï¬°¤À¨É] ¥ÎVBA§å¦¸À°¨ä¥Lexcel ªºVB±M®×³]©w±K½XÂê©w
¥»©«³Ì«á¥Ñ diabo ©ó 2011-2-28 00:31 ½s¿è
¤@ª½µLªk¦¨¥\¡A½Ð¤j®aÀ°¦£¬Ý¬Ýþ¸Ì¦³°ÝÃD¡H- Sub Lock_VBA()
- Dim xlapp As Excel.Application
- Dim wbSource As Excel.Workbook
- Dim LogFileName As Variant
- Dim fname As Variant
- Dim VBA_PWD As String, XLS_PWD As String
-
- '¨ú±o±K½X
- VBA_PWD = [c4] 'VBA password
-
- Set xlapp = New Excel.Application
-
- 'MultiSelect:=True ªí¥Ü¥i½Æ¿ïÀÉ®×
- LogFileName = Application.GetOpenFilename( _
- FileFilter:="ExcelÀÉ(*.xls),*.txt", _
- Title:="½Ð¿ï¨úÀÉ®×", MultiSelect:=True)
-
- '§PÂ_¨Ï¥ÎªÌ¬O§_¦³¿ï¨úÀɮסA©Î«ö¨ú®ø
- If VarType(LogFileName) = vbBoolean Then
- Exit Sub
- End If
-
-
- xlapp.Visible = True
- For Each fname In LogFileName
- Set wbSource = xlapp.Workbooks.Open(CStr(fname))
-
- '±M®×¨S¦³«OÅ@
- If wbSource.VBProject.Protection = 0 Then
-
- DoEvents
-
- With xlapp
- .SendKeys "%{F11}" 'Alt + F11 ¤Á´«¨ìVBAµøµ¡
- .SendKeys "%Te" 'ALT + T ¤u¨ã(ÁcÅ餤¤å¬O(T))-VBprojectÄÝ©Ê(E)
- .SendKeys "^{TAB}" '¤Á´«¨ì¤U¤@¶± VBprojectÄÝ©Ê(E)-«OÅ@
- .SendKeys "{+}" '{+}/{-}¿ï¨ú/¨ú®ø¡uÂê©w±M®×¥H¨ÑÀ˵ø¡v
- .SendKeys "{TAB}", False '²¾¨ì±K½XÄæ¦ì
- .SendKeys VBA_PWD & "{TAB}", True '¿é¤J±K½X
- .SendKeys VBA_PWD '½T»{±K½X
- .SendKeys "{TAB}{ENTER}" '«ö½T©w¶s(¹w³]È)
- .SendKeys "%q" '
- End With
-
- '¦sÀÉ«áÃö³¬¸ÓÀÉ®×
- wbSource.Save
- wbSource.Close SaveChanges:=True
-
- 'MsgBox Dir(fname) & " ±M®×Âê©w§¹¦¨"
-
- Else
-
- '¤£¦sÀÉ«áÃö³¬¸ÓÀÉ®×
- wbSource.Close SaveChanges:=False
-
- 'MsgBox Dir(fname) & " ±M®×¤w¸gÂê©w¡A½Ð¸ÑÂê«á¦A°õ¦æ"
- End If
- Next fname
-
- Set wbSource = Nothing xlapp.Quit
- End Sub
½Æ»s¥N½X
lock_vba.rar (493.61 KB)
|
|
diabo
|
|
|
|
|
- ©«¤l
- 79
- ¥DÃD
- 2
- ºëµØ
- 0
- ¿n¤À
- 193
- ÂI¦W
- 0
- §@·~¨t²Î
- Winwos 7 64 bits
- ³nÅ骩¥»
- Excel 2003/2007
- ¾\ŪÅv
- 20
- ©Ê§O
- ¨k
- ¨Ó¦Û
- TAIPEI
- µù¥U®É¶¡
- 2010-8-25
- ³Ì«áµn¿ý
- 2019-9-20
|
ÁÂÁ kimbal ¡AªGµM¬O³on©Rªº8¬í.......
²{¦b OK ¤F.... |
|
diabo
|
|
|
|
|
- ©«¤l
- 472
- ¥DÃD
- 5
- ºëµØ
- 0
- ¿n¤À
- 485
- ÂI¦W
- 0
- §@·~¨t²Î
- Windows
- ³nÅ骩¥»
- MS Office
- ¾\ŪÅv
- 100
- ©Ê§O
- ¨k
- ¨Ó¦Û
- »´ä
- µù¥U®É¶¡
- 2010-7-4
- ³Ì«áµn¿ý
- 2014-12-28
|
¤@ª½µLªk¦¨¥\¡A½Ð¤j®aÀ°¦£¬Ý¬Ýþ¸Ì¦³°ÝÃD¡H
diabo µoªí©ó 2011-2-26 20:55
sendkeys»Ýn°t¦Xª©±Åã¥Ü§Ö³t«×,¸Õ¸Õ¥[¨Ç¼È°±ªº¥N½X- With xlapp
- .SendKeys "%{F11}" 'Alt + F11 ¤Á´«¨ìVBAµøµ¡
- Application.Wait (Now + TimeValue("0:00:01"))
- .SendKeys "%Te" 'ALT + T ¤u¨ã(ÁcÅ餤¤å¬O(T))-VBprojectÄÝ©Ê(E)
- Application.Wait (Now + TimeValue("0:00:01"))
- .SendKeys "^{TAB}" '¤Á´«¨ì¤U¤@¶± VBprojectÄÝ©Ê(E)-«OÅ@
- Application.Wait (Now + TimeValue("0:00:01"))
- .SendKeys "{+}" '{+}/{-}¿ï¨ú/¨ú®ø¡uÂê©w±M®×¥H¨ÑÀ˵ø¡v
- Application.Wait (Now + TimeValue("0:00:01"))
- .SendKeys "{TAB}", False '²¾¨ì±K½XÄæ¦ì
- Application.Wait (Now + TimeValue("0:00:01"))
- .SendKeys VBA_PWD & "{TAB}", True '¿é¤J±K½X
- Application.Wait (Now + TimeValue("0:00:01"))
- .SendKeys VBA_PWD '½T»{±K½X
- Application.Wait (Now + TimeValue("0:00:01"))
- .SendKeys "{TAB}{ENTER}" '«ö½T©w¶s(¹w³]È)
- Application.Wait (Now + TimeValue("0:00:01"))
- .SendKeys "%q" '
- End With
½Æ»s¥N½X |
|
|
|
|
|
|