VBA来创建一个新的 Excel 文件

前言

其他的宏指令执行的前提条件是创建一个新的xlsx文件,来存储操作完成后的结果.否则会因为缺少操作对象,出现1004错误.

vbscript 复制代码
Sub CreateNewFile()
    Dim xlApp As Object
    Dim xlWB As Object
    
    ' 创建一个新的 Excel 应用程序对象
    Set xlApp = CreateObject("Excel.Application")
    
    ' 禁止显示警告信息和屏幕更新
    xlApp.DisplayAlerts = False
    xlApp.ScreenUpdating = False
    
    ' 创建一个新的工作簿
    Set xlWB = xlApp.Workbooks.Add
    
    ' 在新工作簿中进行一些操作,例如写入数据或设置格式
    
    ' 保存新文件
    xlWB.SaveAs "C:\path\to\your\newfile.xlsx"
    
    ' 关闭工作簿和 Excel 应用程序
    xlWB.Close
    xlApp.Quit
    
    ' 释放对象
    Set xlWB = Nothing
    Set xlApp = Nothing
    
    ' 恢复显示警告信息和屏幕更新
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
End Sub
相关推荐
UR的出不克16 小时前
使用 Python 爬取 Bilibili 弹幕数据并导出 Excel
java·python·excel
wtsolutions17 小时前
Understanding Excel Data Formats - What Excel to JSON Supports
ui·json·excel
ぁず17 小时前
excel想生成一列随机数并删除公式保留值
excel
wtsolutions20 小时前
Real-World Use Cases - How Organizations Use Excel to JSON
json·github·excel
一只小H呀の20 小时前
pandas处理excel数据
excel·pandas
wregjru20 小时前
【操作系统】3.开发工具
excel
wtsolutions1 天前
MCP Service Integration - Excel to JSON for AI and Automation
人工智能·json·excel
wtsolutions1 天前
JSON to Excel Add-in - Seamless Integration Within Excel
json·excel
wtsolutions1 天前
Getting Started with JSON to Excel Web App - Convert in Seconds
json·excel·web app
wtsolutions2 天前
Using the JSON to Excel API - Programmatic Access for Developers
json·excel