|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 zhanglei1371 于 2014-7-27 13:47 编辑
近来笔者在批量用word合并一些文档时遇到个问题,就是在插入第一章、第二章时,无法自动按章节顺序,而是按拼音顺序,因此思索良久,始终没有更好的方法
最后用如下代码解决了问题。代码是用很机械的方法完成的。仅适用于100内的情况
作为讨论,各位看看有没更好的方法和代码,如有更好更快的思路及代码,可跟帖提供,共同学习。
- Sub 按一二三四五六七八九十排序()
- on error resume next
- arr = Array("100#一百", "099#九十九", "098#九十八", "097#九十七", "096#九十六", "095#九十五", "094#九十四", "093#九十三", "092#九十二", "091#九十一", _
- "090#九十", "089#八十九", "088#八十八", "087#八十七", "086#八十六", "085#八十五", "084#八十四", "083#八十三", "082#八十二", "081#八十一", _
- "080#八十", "079#七十九", "078#七十八", "077#七十七", "076#七十六", "075#七十五", "074#七十四", "073#七十三", "072#七十二", "071#七十一", _
- "070#七十", "069#六十九", "068#六十八", "067#六十七", "066#六十六", "065#六十五", "064#六十四", "063#六十三", "062#六十二", "061#六十一", _
- "060#六十", "059#五十九", "058#五十八", "057#五十七", "056#五十六", "055#五十五", "054#五十四", "053#五十三", "052#五十二", "051#五十一", _
- "050#五十", "049#四十九", "048#四十八", "047#四十七", "046#四十六", "045#四十五", "044#四十四", "043#四十三", "042#四十二", "041#四十一", _
- "040#四十", "039#三十九", "038#三十八", "037#三十七", "036#三十六", "035#三十五", "034#三十四", "033#三十三", "032#三十二", "031#三十一", _
- "030#三十", "029#二十九", "028#二十八", "027#二十七", "026#二十六", "025#二十五", "024#二十四", "023#二十三", "022#二十二", "021#二十一" _
- , "020#二十", "019#十九", "018#十八", "017#十七", "016#十六", "015#十五", "014#十四", "013#十三", "012#十二", "011#十一", "010#十", "009#九", _
- "008#八", "007#七", "006#六", "005#五", "004#四", "003#三", "002#二", "001#一")
- With Application.FileDialog(1)
- If .Show <> -1 Then Exit Sub
- For Each f In .SelectedItems
- For i = 0 To UBound(arr)
- If InStr(bn, Split(arr(i), "#")(1)) Then
- strA = Replace(f, Split(arr(i), "#")(1), Split(arr(i), "#")(0)) & "@@" & f + vbNewLine + strA
- Exit For
- End If
- Next
- Next
- End With
- Set fso = CreateObject("scripting.filesystemobject")
- fso.createtextfile("c:\tem$.txt", True).write strA
- Shell "cmd /c type c:\tem$.txt|sort>c:\tem2.txt"
- strB = fso.opentextfile("c:\tem2.txt").readall
- Set fso = Nothing
- arr2 = Split(Left(strB, Len(strB) - 1), vbCrLf)
- For Each m In arr2
- ActiveDocument.Content.InsertAfter Split(m, "@@")(1) + Chr(13)
- Next
- Kill "c:\tem*.txt"
- End Sub
复制代码 此外,最近遇到个奇怪的文档,全选----清除格式居然无法完成,有兴趣的可以看看是什么原因造成的:
补充内容 (2014-8-4 10:29):
17行的bn改为f |
|