Word里生成excel的vba怎么写
时间: 2024-05-27 18:10:33 浏览: 149
vba.rar_Excel VBA_VBA 写入excel_excel_vba excel
以下是生成Excel的VBA代码示例:
Sub ExportToExcel()
Dim MyWorkbook As Object
Dim MyWorksheet As Object
Dim FileName As String
'Create a new workbook
Set MyWorkbook = CreateObject("Excel.Application")
'Make Excel visible
MyWorkbook.Visible = True
'Add a new worksheet
Set MyWorksheet = MyWorkbook.Workbooks.Add.Sheets.Add
'Modify worksheet data
MyWorksheet.Range("A1").Value = "Hello World"
'Make a save-as dialog box appear
FileName = Application.GetSaveAsFilename(FileFilter:="Excel Files (*.xls), *.xls")
If FileName <> False Then
'Move the worksheet to a new workbook
MyWorksheet.Move
'Save the new workbook
MyWorkbook.ActiveWorkbook.SaveAs FileName:=FileName, FileFormat:=xlWorkbookNormal
End If
'Close Excel
MyWorkbook.Quit
End Sub
请注意,此代码仅供参考,您可能需要根据您的特定要求进行修改。
阅读全文