메인 컨텐츠로 가기

명령 단추를 사용하여 활성 워크 시트를 Excel에서 PDF 파일로 저장하는 방법은 무엇입니까?

Microsoft Excel에서 작업하는 동안 활성 워크 시트를 PDF 파일로 저장하는 문제에 직면 할 수 있습니다. 이 기사에서는 명령 단추를 통해 VBA 코드를 사용하여 활성 워크 시트를 PDF 파일로 저장하는 방법을 배울 수 있습니다. 또한 활성 통합 문서의 범위 또는 각 워크 시트를 개별 PDF 파일로 저장하려는 경우에도이 문서가 도움이 될 수 있습니다.

명령 단추를 사용하여 활성 워크 시트를 VBA 코드로 PDF 파일로 저장
Excel 용 Kutools를 사용하여 활성 또는 각 워크 시트를 개별 PDF 파일로 쉽게 저장


명령 단추를 사용하여 활성 워크 시트를 VBA 코드로 PDF 파일로 저장

다음 VBA 코드를 실행하여 명령 단추를 클릭하여 활성 워크 시트를 PDF 파일로 저장할 수 있습니다. 다음과 같이하십시오.

1. 먼저 변환 된 새 PDF 파일을 저장하기 위해 PDF라는 폴더를 만들어야합니다. 여기에서 내 로컬 디스크 (C :)에이 폴더를 만듭니다.

2. 클릭하여 명령 단추를 삽입하십시오 개발자 > 끼워 넣다 > 명령 단추 (ActiveX 컨트롤). 스크린 샷보기 :

2. 그런 다음 새 행을 추가해야하는 워크 시트에 명령 단추를 그리고 명령 단추를 마우스 오른쪽 단추로 클릭하고 등록 오른쪽 클릭 메뉴에서.

3. 에서 등록 대화 상자에서 명령 단추의 표시된 텍스트를 표제 아래 상자 분류 된 탭을 클릭 한 다음 대화 상자를 닫습니다.

아래 스크린 샷과 같이 Command Button의 표시된 텍스트가 변경된 것을 볼 수 있습니다.

4. 명령 단추를 다시 마우스 오른쪽 단추로 클릭 한 다음 코드보기 오른쪽 클릭 메뉴에서.

5. 오프닝에서 응용 프로그램 용 Microsoft Visual Basic 창에서 코드 창의 원래 코드를 다음 VBA 코드로 바꾸십시오.

VBA 코드 : 활성 워크 시트를 PDF로 저장하는 명령 단추

Private Sub CommandButton1_Click()
    Application.ScreenUpdating = False
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
            Filename:="C:\PDF\Export.pdf", _
            OpenAfterPublish:=False
    Application.ScreenUpdating = True
End Sub

주의 사항: 코드에서 CommandButton1은 활성 시트를 PDF 파일로 저장하는 데 사용할 명령 단추 이름입니다. "C : \ PDF \ Export.pdf"는 저장 PDF 파일의 경로 및 이름입니다.

6. 누르세요 다른 + Q 키를 동시에 닫아 응용 프로그램 용 Microsoft Visual Basic 창문. 그런 다음 디자인 모드 아래 개발자 탭.

이제 명령 버튼을 클릭하면 활성 워크 시트가 내보내기라는 이름의 PDF 파일로 저장되고 지정된 위치에 있습니다.


Excel 용 Kutools를 사용하여 각 워크 시트를 활성 통합 문서의 개별 PDF 파일로 저장하십시오.

여기에서 통합 문서 분할 ~의 유용성 Excel 용 Kutools 활성 워크 시트를 PDF 파일로 쉽게 저장합니다. 또한이 유틸리티를 사용하여 현재 통합 문서의 각 워크 시트를 개별 PDF 파일로 저장할 수도 있습니다.

신청하기 전에 Excel 용 Kutools, 제발 먼저 다운로드하여 설치하십시오..

1. 통합 문서에서 각 워크 시트를 개별 PDF 파일로 저장 한 다음 쿠툴즈 플러스 > 통합 문서 > 통합 문서 분할. 스크린 샷보기 :

2. 에서 통합 문서 분할 대화 상자에서 다음과 같이 구성하십시오.

2.1) 활성 시트 이름 만 확인하십시오. 워크 시트 이름 상자;
2.2) 선택 PDF (*. pdf) 옵션에서 형식으로 저장 드롭 다운 목록;
2.3) 클릭 스플릿 버튼을 누른 다음 폴더 선택 대화 상자가 나타나면 PDF 파일을 저장할 폴더를 지정하십시오.

그러면 선택한 워크 시트가 즉시 PDF 파일로 저장됩니다.

노트:

1. 워크 시트 이름 상자에서 여러 워크 시트 이름을 확인하여 한 번에 개별 pdf 파일로 저장할 수 있습니다.
2. 워크 시트를 pdf 파일로 저장하는 경우를 제외하고 워크 시트를 txt로 저장할 수 있습니다. 또는 csv. 당신이 필요로하는 파일.

  이 유틸리티의 무료 평가판 (30 일)을 받으려면 그것을 다운로드하려면 클릭하십시오을 클릭 한 다음 위 단계에 따라 작업 적용으로 이동합니다.


데모 : Excel 용 Kutools를 사용하여 선택 항목 또는 각 워크 시트를 PDF로 저장


관련 기사:

최고의 사무 생산성 도구

🤖 Kutools AI 보좌관: 다음을 기반으로 데이터 분석을 혁신합니다. 지능형 실행   |  코드 생성  |  사용자 정의 수식 만들기  |  데이터 분석 및 차트 생성  |  Kutools 기능 호출...
인기 기능: 중복 항목 찾기, 강조 표시 또는 식별   |  빈 행 삭제   |  데이터 손실 없이 열이나 셀 결합   |   수식없이 반올림 ...
슈퍼 조회: 다중 기준 VLookup    다중 값 VLookup  |   여러 시트에 걸친 VLookup   |   퍼지 조회 ....
고급 드롭다운 목록: 드롭다운 목록을 빠르게 생성   |  종속 드롭다운 목록   |  다중 선택 드롭 다운 목록 ....
열 관리자: 특정 개수의 열 추가  |  열 이동  |  Toggle 숨겨진 열의 가시성 상태  |  범위 및 열 비교 ...
특색 지어진 특징: 그리드 포커스   |  디자인보기   |   큰 수식 바    통합 문서 및 시트 관리자   |  리소스 라이브러리 (자동 텍스트)   |  날짜 선택기   |  워크 시트 결합   |  셀 암호화/해독    목록으로 이메일 보내기   |  슈퍼 필터   |   특수 필터 (굵게/기울임꼴/취소선 필터링...) ...
상위 15개 도구 세트12 본문 도구 (텍스트 추가, 문자 제거,...)   |   50+ 거래차트 유형 (Gantt 차트,...)   |   40+ 실용 방식 (생일을 기준으로 나이 계산,...)   |   19 삽입 도구 (QR 코드 삽입, 경로에서 그림 삽입,...)   |   12 매출 상승 도구 (숫자를 단어로, 환율,...)   |   7 병합 및 분할 도구 (고급 결합 행, 셀 분할,...)   |   ... 그리고 더

Excel용 Kutools로 Excel 기술을 강화하고 이전과는 전혀 다른 효율성을 경험해 보세요. Excel용 Kutools는 생산성을 높이고 시간을 절약하기 위해 300개 이상의 고급 기능을 제공합니다.  가장 필요한 기능을 얻으려면 여기를 클릭하십시오...

상품 설명


Office Tab은 Office에 탭 인터페이스를 제공하여 작업을 훨씬 쉽게 만듭니다.

  • Word, Excel, PowerPoint에서 탭 편집 및 읽기 사용, Publisher, Access, Visio 및 Project.
  • 새 창이 아닌 동일한 창의 새 탭에서 여러 문서를 열고 만듭니다.
  • 생산성을 50% 높이고 매일 수백 번의 마우스 클릭을 줄입니다!
Comments (33)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Ich nutze diese Zeilen und das funktioniert auch gut, mein Problem ist nur, sollte diese Datei bereits vorhanden sein, WIRD diese einfach überschrieben!
Wie kann ich das vermeiden, es sollte eine Meldung kommen, Datei existiert bereits und es soll beendet werden?


Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:="X:\firmen\Buchhaltung\Rechnungs-Kopie_Ackermann Service GmbH\2022\RK-Abrechnung\" & ActiveSheet.Range("G1") & ".pdf", _
OpenAfterPublish:=True
Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
Hi Sascha,
The following VBA code can help. Please give it a try.

Private Sub CommandButton1_Click()
'Updated by Extendoffice 20221230
    Dim xPDFName As String
    Dim xPDFPath As String
    Dim xObjFS As Object
    Dim xNum As Integer
    Dim xStr As String
    
    xPDFName = "Export" 'The file name
    xPDFPath = "D:\work\Jan\test\" 'The file path
    Application.ScreenUpdating = True
    On Error Resume Next
    Set xObjFS = CreateObject("Scripting.FileSystemObject")
    xStr = xPDFPath & xPDFName & ".pdf"
    xNum = 1
    If xObjFS.FileExists(xStr) Then
    xResponse = MsgBox("The file already exists, do you want to overwrite it?", vbYesNo, "www.extendoffice.com", "", 0)
       If xResponse <> vbYes Then
       Exit Sub
      End If
    End If
    Application.ScreenUpdating = False
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
            FileName:=xStr, _
            OpenAfterPublish:=False
    Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
Ich nutze diese Zeilen und das funktioniert auch gut, mein Problem ist nur, sollte diese Datei bereits vorhanden sein, wird diese einfach überschrieben!
Wie kann ich das vermeiden, es sollte eine Meldung kommen, Datei existiert bereits und es soll beendet werden?
This comment was minimized by the moderator on the site
When I run the below it creates a local version of the PDF automatically - how do I stop this from automatically saving?

Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
OpenAfterPublish:=True
Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
Hi James,
Do you want to pop up a window to select a folder to save the PDF file manually?
This comment was minimized by the moderator on the site
Hi Crystal, ideally yes so I can then choose where to save the PDF.
This comment was minimized by the moderator on the site
H James,

The following VBA code can help you solve the problem.
Note: You can't handle both the destination and the file name at the same time. After adding the following VBA code, when you click the button, a dialog box will pop up for you to select a destination folder. After selecting a destination folder, a box will pop up for you to give a name to the PDF file.

Private Sub CommandButton1_Click()
'Updated by Extendoffice 20221223
    Dim xDlg As FileDialog
    Dim xFolder As Variant
    Set xDlg = Application.FileDialog(msoFileDialogFolderPicker)
    Dim xStrName As String
    If xDlg.Show <> -1 Then Exit Sub
    
    xFolder = xDlg.SelectedItems(1)
    
    xStart = InputBox("file name", "KuTools for Excel", ActiveSheet.Name & ".pdf")

    Application.ScreenUpdating = False

    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
            Filename:=xFolder & "\" & xStart, _
            OpenAfterPublish:=False
    Application.ScreenUpdating = True

End Sub
This comment was minimized by the moderator on the site
Whenever I run this it saves a PDF to my local drive where the excel sheets saved, how do I stop this from auto saving?

Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
OpenAfterPublish:=True
Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
Hi Team,

Just wondering if anyone could help with changing the destination of the created file to any user's desktop? My compnay doesn't allow access to C: so the script doesn't work.

MANY MANY MANY thanks!
This comment was minimized by the moderator on the site
Hi Ben Stoddart,
You just need to open any folder on your desktop and copy the folder path in the address box, then replace the folder path in the VBA code with the path you copied.
Here is the new Filename line (please replace the Username with your own username), Export.pdf is the name and the file extension of the PDF file:
Filename:="C:\Users\Username\Desktop\PDF\Export.pdf", _
This comment was minimized by the moderator on the site
Goededag

is het mogelijk om een filmpje of een voorbeeld excelblad te maken voor de Command-Knop Om Een ​​Actief Werkblad Op Te Slaan Als PDF-Bestand Met VBA-Code.
kom er niet helemaal uit met de codes.
alvast bedankt
This comment was minimized by the moderator on the site
Hi max,
Sorry I don't understand what you mean. You may need to attach a screenshot of what you are trying to do. Sorry for the inconvenience.
This comment was minimized by the moderator on the site
Что это за кнопка - "другой" + Q клавиши одновременно" ? Не поняла что нажимать, подскажите, пожалуйста
This comment was minimized by the moderator on the site
Hi Диана,
It is the "Alt" key on your keyboard. Microsoft Excel allows users to press the "Alt" + "Q" keys to close the Microsoft Visual Basic for Applications window and return to the worksheet.
This comment was minimized by the moderator on the site
Hallo,

ich nutze diese Zeilen und möchte das eine Zelle als Dateiname verwenden wird!
Kann mir jemand ein Tipp geben?


Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:="c:/" & G3 & ".pdf", _
OpenAfterPublish:=False
Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
Hi Sascha,
The following code can help. Before applying the code, please change 'C:\Users\Win10x64Test\Documents\PDF' in the fourth line to you own destination folder path.
Private Sub CommandButton1_Click()
'Updated by Extendoffice 20220929
    Application.ScreenUpdating = False
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
            Filename:="C:\Users\Win10x64Test\Documents\PDF\" & Range("G3").Value, _
            OpenAfterPublish:=False
    Application.ScreenUpdating = True
End Sub
This comment was minimized by the moderator on the site
Hallo,

kann jemand mir helfen?

Ich nutze diese Zeilen und möchte jedoch, das aus dem Blatt ein Zellenwert als Dateiname gespeichert wird:

Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:="C:\PDF\Export.pdf", _
OpenAfterPublish:=False
Application.ScreenUpdating = True
End Sub

Danke
This comment was minimized by the moderator on the site
ive followed the code, this is what i have:

Private Sub CommandButton2_Click()
Application.ScreenUpdating = False
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=Range("P2"), _
OpenAfterPublish:=True
Application.ScreenUpdating = True
End Sub

i need the file to save to the location that the orignal file is located. also need a copy of the excel file to save aswell with the same name.
This comment was minimized by the moderator on the site
Hi Matt Bentley,
The code works perfectly. Thank you for sharing.
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations