我正在努力將我的 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
uj5u.com熱心網友回復:
備份為 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
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/358519.html
上一篇:如何根據計數器變數的值參考命名范圍中特定的、不斷變化的行?
下一篇:滑動擴展影片旁邊的專案
