在EXCEL中用按钮将指定单元格的数据作为新建doc文档的文件名,并保存的代码:
Sub 按钮2_单击() ' Creates memos in word using Automation (late binding) Dim wordApp As Object Dim Data As Range, message As String Dim Records As Integer, I As Integer Dim Region As String, SalesAmt As String, SalesNum As String Dim SaveAsName As String 'Start Word and create an object Set wordApp = CreateObject("Word.Application") ' Information from worksheet Set Data = Sheets("Sheet1").Range("A2") 'Assign current data to variables Region = Data.Cells(1, 3).Value ' Determine the file name SaveAsName = ThisWorkbook.Path & "\" & Region & ".doc" ' Send commands to Word With wordApp .Documents.Add .ActiveDocument.SaveAs FileName:=SaveAsName End With ' Kill the object wordApp.Quit Set wordApp = Nothing ' Reset status bar Application.StatusBar = "" MsgBox Records & " memos were created and saved in " & ThisWorkbook.Path End Sub [em26][em26][em26][em26][em26][em26][em26][em26][em26] |