Bearbeiten:

Bearbeiten:

Ich habe der Excel-Tabelle eine Schaltfläche hinzugefügt und wenn ich jetzt auf diese Schaltfläche klicke, wird die Tabelle unter einem bestimmten Pfad und einem bestimmten Namen, aber im PDF-Format gespeichert.

Ich möchte dieses Blatt einfach im Excel-Format (.xlsx) speichern. also

Sub PDFActiveSheet2()

Dim ws As Worksheet
Dim strFile As String

On Error GoTo errHandler

strFile = "m:\formats\" & Range("H8")
Set ws = ActiveSheet

ws.ExportAsFixedFormat _
    Type:=xlTypePDF, _
    Filename:=strFile, _
    Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, _
    IgnorePrintAreas:=False, _
    OpenAfterPublish:=False

MsgBox "file has been created."

exitHandler:
        Exit Sub
errHandler:
        MsgBox "Could not create the file"
        Resume exitHandler

End Sub

Was muss ich ändern?

Antwort1

Ändern Sie Ihren folgenden Code von

ws.ExportAsFixedFormat _
    Type:=xlTypePDF, _
    Filename:=strFile, _
    Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, _
    IgnorePrintAreas:=False, _
    OpenAfterPublish:=False

Zum folgenden Code

ActiveWorkbook.SaveAs Filename:="C:\Users\46506090\Desktop\Book1.xlsm", _
            FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False

Ändern Sie den Pfad (C:\Benutzer\46506090\Desktop\Book1.xlsm) zu dem, was Sie möchten, und sehen Sie, ob es funktioniert.

CreateBackup:=False  

Dies ist optional

Bearbeiten:

Der komplette Code

Option Explicit

Sub Button1_Click()
'Sub PDFActiveSheet2()

Dim ws As Worksheet
Dim strFile As String

On Error GoTo errHandler

strFile = "m:\formats\" & Range("H8")
Set ws = ActiveSheet

ActiveWorkbook.SaveAs Filename:="C:\Users\46506090\Desktop\Book1.xlsm", _
            FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
'Comment: Replace "C:\Users\46506090\Desktop\Book1.xlsm" to your desired filename
MsgBox "file has been created."

exitHandler:
        Exit Sub
errHandler:
        MsgBox "Could not create the file"
        Resume exitHandler

End Sub

Antwort2

Korrektur zur anderen Antwort: Es sollte nur einen Speicherort geben


Option Explicit

Sub Button1_Click()
'Sub PDFActiveSheet2()

Dim ws As Worksheet
Dim strFile As String

On Error GoTo errHandler

strFile = "C:\Users\yourName\Desktop\Book1.xlsm"
'Comment: Replace "C:\Users\yourName\Desktop\Book1.xlsm" to your desired filename

Set ws = ActiveSheet

ActiveWorkbook.SaveAs Filename:=strFile, _
            FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False

MsgBox "file has been created."

exitHandler:
        Exit Sub
errHandler:
        MsgBox "Could not create the file"
        Resume exitHandler

End Sub

verwandte Informationen