首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将XLSM保存到XLSX

将XLSM保存到XLSX
EN

Stack Overflow用户
提问于 2021-11-16 14:16:44
回答 1查看 71关注 0票数 2

我正在努力将我的XLSM转换成XLSX之前是转换成File..it,我试图改变一点,但没有成功。

我想使用与工作簿相同的名称,但只使用XLSX格式。

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-16 23:14:36

备份为XLSX

代码语言:javascript
复制
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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69990757

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档