Saving Workbook as .pdf & .xlsm with specific path and filename, FileFormat:=51 no longer works

inBizness4u

New Member
Joined
Mar 25, 2019
Messages
1
This VBA Code below worked for several years and all of a sudden it stops at the line I highlighted in BOLD (ending with FileFormat:=51. This Purchase Order Form with VBA Code saves my PO's in .pdf & .xlsm and adds a line to my log tab, then clears the form. It works on my computer at home which has Microsoft Office 2010 but does not work at work where my computer is Office 365 with Windows 10. I am very happy to share this with anyone that can figure out why it now longer works.

Sub POReport()

Dim myFile As String, lastRow As Long

'Saves the PO-Template in .pdf format with cells (G6), (F11) and (C6) & extention .pdf

myFile = "Desktop\OCS-POs" & "OCS-POs-" & Sheets("OCS-PO-Template").Range("G6") & "-" & Sheets("OCS-PO-Template").Range("F11") & "-" & Sheets("OCS-PO-Template").Range("C6") & ".pdf"

lastRow = Sheets("OCS-PO-Log").UsedRange.SpecialCells(xlCellTypeLastCell).Row + 1

'Transfer data to Log
'Copy the information from the cells PO number (G6), Project Name (F11) and Contractor (C6) to the log

Sheets("OCS-PO-Log").Cells(lastRow, 1) = Now
Sheets("OCS-PO-Log").Cells(lastRow, 2) = Sheets("OCS-PO-Template").Range("F6")
Sheets("OCS-PO-Log").Cells(lastRow, 3) = Sheets("OCS-PO-Template").Range("G6")
Sheets("OCS-PO-Log").Cells(lastRow, 4) = Sheets("OCS-PO-Template").Range("C14")
Sheets("OCS-PO-Log").Cells(lastRow, 5) = Sheets("OCS-PO-Template").Range("F11")
Sheets("OCS-PO-Log").Cells(lastRow, 6) = Sheets("OCS-PO-Template").Range("F10")
Sheets("OCS-PO-Log").Cells(lastRow, 7) = Sheets("OCS-PO-Template").Range("C6")
Sheets("OCS-PO-Log").Cells(lastRow, 8) = Sheets("OCS-PO-Template").Range("C7")
Sheets("OCS-PO-Log").Cells(lastRow, 9) = Sheets("OCS-PO-Template").Range("G32")

Sheets("OCS-PO-Log").Hyperlinks.Add Anchor:=Sheets("OCS-PO-Log").Cells(lastRow, 10), Address:=myFile, TextToDisplay:=myFile

'Create PO-Template in .pdf format
'When the .pdf copy is saved, it needs to select and to save only the PO-Log that are equal to the number of issues

Application.DisplayAlerts = False

ActiveWorkbook.ActiveSheet.SaveAs "Desktop\OCS-POs" & "OCS-POs-" & Sheets("OCS-PO-Template").Range("G6") & "-" & Sheets("OCS-PO-Template").Range("F11") & "-" & Sheets("OCS-PO-Template").Range("C6") & ".xlsx", FileFormat:=51

ActiveWorkbook.ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=myFile
Application.DisplayAlerts = True

'The cells are cleared
Range("B16:F30") = ""
Range("F10:F12") = ""
Range("C7") = ""
Range("C31") = ""
Range("B32") = ""

ActiveWorkbook.SaveAs Filename:= _
"Desktop\OCS-PO-Template.xlsm", _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False

Application.DisplayAlerts = True

'This allows the PO-Template to change PO number when clicked

Range("G6").Value = Range("G6").Value + 1

ActiveWorkbook.Save

End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Any error messages?
Turn alerts on while problem is ssolved. You are probably missing some important messages.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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