Excel 按特定名称保存文档的vba代码
我有800份工资单,我只能在一份文件里拿到。每次我都要一张一张地保存工资单。我需要vba代码,可以保存他们的名字工资单。下面的代码我尝试了,但没有结果Excel 按特定名称保存文档的vba代码,excel,vba,Excel,Vba,我有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
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
(1) 我认为你用错了标签;这看起来像“word vba”,它与“excel vba”非常不同。(2) (2)您的意思是使用“doc”的扩展名吗?扩展名“doc”最后一次与Word 2003一起使用。(1)我认为您使用了错误的标签;这看起来像“word vba”,它与“excel vba”非常不同。(2) (2)您的意思是使用“doc”的扩展名吗?扩展名“doc”最后一次与Word 2003一起使用。