Advertisement
Guest User

Untitled

a guest
Jul 28th, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. /SN001/SN-1.doc
  2. /SN002/SN-2.doc
  3. .
  4. .
  5. .
  6. /SN080/SN-80.doc
  7.  
  8. Private Sub Document_Open()
  9. '
  10. ' Document_Open Macro
  11. '
  12. '
  13. Application.OnTime (Now + TimeValue("00:00:02")), "ProcessActiveDocument"
  14.  
  15. End Sub
  16.  
  17. Sub ProcessActiveDocument()
  18. Dim BmkNm As String, BmkRng As Range, FileName As String
  19. BmkNm = "FileName"
  20. FileName = ActiveDocument.Name
  21. If InStrRev(FileName, ".") > 0 Then FileName = Left(FileName, InStrRev(FileName, ".") - 1)
  22. If ActiveDocument.Bookmarks.Exists(BmkNm) Then
  23. Set BmkRng = ActiveDocument.Bookmarks(BmkNm).Range
  24. If BmkRng.Text = FileName Then Exit Sub
  25. BmkRng.Text = FileName
  26. ActiveDocument.Bookmarks.Add BmkNm, BmkRng
  27. Else
  28. MsgBox "Bookmark: " & BmkNm & " not found."
  29. End If
  30. Set BmkRng = Nothing
  31. End Sub
  32.  
  33. import os
  34. import shutil
  35.  
  36. ref_dir_base = "C:/SN"
  37. word_doc = 'SN-'
  38. word_ext = '.doc'
  39. ref_num = 1
  40. ref_str = str(1000+ref_num)[1:]
  41. begin_num = 2
  42. stop_num = 12
  43. word_exec = '"C:/Program Files (x86)/Microsoft Office/Office14/Winword.exe"'
  44.  
  45.  
  46. for i in range(begin_num, stop_num+1):
  47. num_str = str(1000+i)[1:]
  48. shutil.copytree(ref_dir_base+ref_str, ref_dir_base+num_str)
  49. old_doc_name = word_doc + str(ref_num) + word_ext
  50. new_doc_name = word_doc + str(i) + word_ext
  51. new_path = ref_dir_base + num_str + os.altsep
  52. os.rename(new_path + old_doc_name, new_path + new_doc_name)
  53.  
  54.  
  55. for i in range(begin_num, stop_num+1):
  56. num_str = str(1000+i)[1:]
  57. new_doc_name = word_doc + str(i) + word_ext
  58. new_path = ref_dir_base + num_str + os.altsep
  59. exec_param = '"'+new_path+new_doc_name + '"'
  60. exec_str = '"'+word_exec+' '+exec_param +'"'
  61. os.startfile(exec_param)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement