Convert macro enable file to excel file with specific naming convention

Bathur01

New Member
Joined
Jan 4, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
How would we modify this script to convert the file to .xlsx ?

Sub PDFActiveSheet()
'www.contextures.com
'for Excel 2010 and later
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"
strTime = Format(Now(), "mmmm dd, yyyy\_hhmm AM/PM")

'get active workbook folder, if saved
strPath = wbA.path
If strPath = "" Then
'strPath = Application.DefaultFilePath
strPath = "C:\Users\bthurman\OneDrive - General Glass\1 - Desktop\Quotes"
End If
strPath = strPath & "\"

'replace spaces and periods in sheet name
strName = Replace(wsA.Name, " ", "")
strName = Replace(strName, ".", "_")
strName = Range("D3") & " - " & Range("I7") & " - " & Range("L7")

'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")

'export to PDF if a folder was selected
If MyFile <> "False" Then
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
End If

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

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
I'm not certain what your posted macro is intended to do. There are lots of things included that don't seem to be utilized in the saved file.

In any case, the following macro will save SHEET1 as xlsx to the Desktop :

VBA Code:
Sub SaveSht1ToDesktop()

    Dim Dsktop As String, xlsxFile As String, xlsxPath As String, str As String
    
        Dsktop = CreateObject("WScript.Shell").SpecialFolders("Desktop") & "\"

        xlsxFile = UCase(str) & " Search Output List.xlsx"
        xlsxPath = "" & Dsktop & UCase(str) & xlsxFile
        ActiveWorkbook.Sheets(Array("Sheet1")).Copy
        
        Application.DisplayAlerts = False
        ActiveWorkbook.SaveAs Filename:=xlsxPath, FileFormat _
            :=51, CreateBackup:=False
        Application.DisplayAlerts = True
        ActiveWorkbook.Close
            
End Sub
 
Upvote 0
Thank you for taking a stab at this. The original vba script was used to convert an excel document into a PDF file. It also provided the naming convention for the file. I would like to keep all of the naming convention and save the file as an ".XLSX" versus a macro enabled file. Can you assist with that?
 
Upvote 0

Forum statistics

Threads
1,214,951
Messages
6,122,449
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top