1
Excelブックで各シートの個別のpdfを作成しようとしています。これは私が使用しているコードです。Excelマクロでpdfsを作成する
Sub CreatePdfs()
' CreatePdfs Macro
' Keyboard Shortcut: Ctrl+o
Dim ws As Worksheet
Dim wsA As Worksheet
Dim wbA As Workbook
Dim strPath As String
Dim strFile As String
Dim strPathFile As String
Dim myFile As Variant
For Each ws In Worksheets
Set wbA = ActiveWorkbook
Set wsA = ActiveSheet
strPath = wbA.Path
If strPath = "" Then
strPath = Application.DefaultFilePath
End If
strPath = strPath & "\"
strName = Replace(wsA.Name, " ", "")
strName = Replace(strName, ".", "_")
strFile = strName & ".pdf"
strPathFile = strPath & strFile
ws.Select
nm = wsA.Name
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=strPathFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Next ws
End Sub
これは「ほとんど」機能します。それは、各シート(それが想定されている)ごとに別々のpdfファイルを作成し、Excelファイルと同じフォルダに保存しますが、間違って名前を付けます。たとえば、1,2,3,4という名前のワークブックに4枚のシートがある場合、シート2をpdfとして作成し、それに「1」という名前を付けます。 3は「2」、4は「3」、1は「4」となります。
コード内に何か不具合があります。
感謝を試してみてください。これからマクロを整理しました。それを同じフォルダに保存しなかったので、それをちょっと二本にしました。それは各ファイル名の冒頭にあるパスの一部の上にあるフォルダにあります。それは今ロッキングしている。約2分で4つのpdfを作ろう! –
あなたの問題が分類されることを願っていますか? :) –