gpt4 book ai didi

excel - 将 XLSM 保存到 XLSX

转载 作者:行者123 更新时间:2023-12-04 20:22:12 25 4
gpt4 key购买 nike

我正在努力将我的 XLSM 转换为 XLSX 文件..它是在转换为 PDF 之前,我试图改变一点但没有成功。
我想与工作簿具有相同的名称,但只是 XLSX 格式。

Sub xlsmtoxlsx()
Dim PathFile As String
Dim PathArray() As String
Dim PathPDF As String

'Get file path
PathFile = Application.ThisWorkbook.FullName

'Split file path in path and file ending
PathArray() = Split(PathFile, ".")

'Creat file path with ".pdf" ending
PathPDF = PathArray(0) & ".xlsx"

'PDF File is saved in directory of workbook
ActiveSheet.ExportAsFixedFormat Type:=xlTypeXlsx, Filename:= _
PathPDF, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=True

'Closes Workbook after generating PDF
ActiveWorkbook.Saved = True
Application.Quit

最佳答案

备份为 XLSX

Option Explicit

Sub BackupAsXLSX()

' Create a reference to the source workbook.
Dim swb As Workbook: Set swb = ThisWorkbook ' workbook containing this code

' Determine the destination file path ('FullName').
Dim sFilePath As String: sFilePath = swb.FullName
Dim DotPosition As Long: DotPosition = InStrRev(sFilePath, ".")
Dim dFilePath As String: dFilePath = Left(sFilePath, DotPosition) & "xlsx"

Application.ScreenUpdating = False

' Copy all sheets to a new (destination) workbook.
swb.Sheets.Copy
Dim dwb As Workbook: Set dwb = ActiveWorkbook
' Save and close the destination workbook.
Application.DisplayAlerts = False ' overwrite without confirmation
dwb.SaveAs Filename:=dFilePath, FileFormat:=xlOpenXMLWorkbook
Application.DisplayAlerts = True
dwb.Close SaveChanges:=False

Application.ScreenUpdating = True

' Inform.
MsgBox "XLSX backup created.", vbInformation

' Note that the source workbook hasn't been modified in any way.

End Sub

关于excel - 将 XLSM 保存到 XLSX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69990757/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com