用于按特定名称保存文档的vba代码

时间:2016-05-01 03:59:49

标签: excel-vba vba excel

我有800个工作单的工资单,我只能在单个文件中获得。每次必须一次一个地保存工资单。我需要vba代码,可以通过他们的名字节省工资单。我试过以下代码但没有结果。

Sub BreakOnPage()
Dim my_filename As String
Dim ss As String
   ' Used to set criteria for moving through the document by page.
   Application.Browser.Target = wdBrowsePage

   For i = 1 To ActiveDocument.BuiltInDocumentProperties("Number of Pages")


      'Select and copy the text to the clipboard.
      ss = ActiveDocument.Bookmarks("asam").Range.Text
      ActiveDocument.Bookmarks("\page").Range.Copy


      ' Open new document to paste the content of the clipboard into.
      Documents.Add
      Selection.Paste
' Removes the break that is copied at the end of the page, if any.
      Selection.TypeBackspace
      Selection.TypeBackspace
       Selection.TypeBackspace
      ChangeFileOpenDirectory "E:\raju"
      DocNum = DocNum + 1
      Selection.MoveUp Unit:=wdScreen, Count:=5
        Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
        Selection.Copy
    my_filename = Selection
      ActiveDocument.SaveAs FileName:=Namevariable & ss & ".doc"
      ActiveDocument.Close

      ' Move the selection to the next page in the document.
      Application.Browser.Next
   Next i
   ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub

0 个答案:

没有答案