Pinaceous
Well-known Member
- Joined
- Jun 11, 2014
- Messages
- 1,124
- Office Version
- 365
- Platform
- Windows
Hi All,
I'm using this sub to create a PDF from an Excel's worksheet.
It works really great!
Now, after careful review of my posted code below, is it possible to create a DOCX in lieu of the PDF?
I've tried to rearrange, modify, adjust, change this code to fit this DOCX creation, but I cannot.
Can someone please help me to change this code to produce a DOCX not a PDF??
Many thanks in advance.
Respectfully,
Pinaceous
I'm using this sub to create a PDF from an Excel's worksheet.
It works really great!
Now, after careful review of my posted code below, is it possible to create a DOCX in lieu of the PDF?
I've tried to rearrange, modify, adjust, change this code to fit this DOCX creation, but I cannot.
Can someone please help me to change this code to produce a DOCX not a PDF??
Code:
Sub CreatePDF()
Dim wsA As Worksheet
Dim wbA As Workbook
Dim strTime As String
Dim strName As String
Dim strPath As String
Dim strFile As String
Dim strPathFile As String
Dim myFile As Variant
On Error GoTo errHandler
Set wbA = ActiveWorkbook
Set wsA = ActiveSheet
strTime = Format(Now(), "yyyymmdd\_hhmm")
'get active workbook folder, if saved
strPath = wbA.Path
If strPath = "" Then
strPath = Application.DefaultFilePath
End If
strPath = strPath & "\"
'replace spaces and periods in sheet name
strName = Replace(wsA.Name, " ", " ")
strName = Replace(strName, ".", "_")
'create default name for savng file
strFile = strName & "_" & strTime & ".pdf"
strPathFile = strPath & strFile
'use can enter name and
' select folder for file
myFile = Application.GetSaveAsFilename _
(InitialFileName:=strPathFile, _
FileFilter:="PDF Files (*.pdf), *.pdf", _
Title:="Select Folder and FileName to save")
Select Case True
'export to PDF if a folder was selected
Case myFile <> "False"
wsA.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=myFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
'confirmation message with file info
MsgBox "PDF file has been created: " _
& vbCrLf _
& myFile
Exit Sub
Case myFile <> "True"
Application.CutCopyMode = False 'Clear Clipboard
MsgBox "Not CREATING PDF!!"
Exit Sub
End Select
Exit Sub
exitHandler:
Exit Sub
errHandler:
MsgBox "Could not create PDF file"
Resume exitHandler
End Sub
Many thanks in advance.
Respectfully,
Pinaceous
Last edited: