Hi,
I have the code below that works great for me and some users but for other users who use my template it looks like someone has resized all the columns but ONLY when they use the below code:
The spreadsheets looks correct on their screen when in Excel but change when exporting to PDF.
What could cause this and is there something I can do in my code?
Thanks in advance!
I have the code below that works great for me and some users but for other users who use my template it looks like someone has resized all the columns but ONLY when they use the below code:
VBA Code:
Sub SavePDF()
Dim xSht As Worksheet
Dim xFileDlg As FileDialog
Dim xFolder As String
Dim xYesorNo As Integer
Dim xOutlookObj As Object
Dim xEmailObj As Object
Dim xUsedRng As Range
Set xSht = ActiveSheet
Set xFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
If xFileDlg.Show = True Then
xFolder = xFileDlg.SelectedItems(1)
Else
MsgBox "Saving cancelled. Please specify a folder to save the PDF into.", vbCritical, "PDF Not Saved"
Exit Sub
End If
xFolder = xFolder + "\" + "Quote " + Range("L4") + ".pdf"
'Check if file already exist
If Len(Dir(xFolder)) > 0 Then
xYesorNo = MsgBox(xFolder & " already exists." & vbCrLf & vbCrLf & "Do you want to overwrite it?", _
vbYesNo + vbQuestion, "File Exists")
On Error Resume Next
If xYesorNo = vbYes Then
Kill xFolder
Else
MsgBox "if you don't overwrite the existing PDF, I can't continue." _
& vbCrLf & vbCrLf & "Press OK to exit this macro.", vbCritical, "Exiting Macro"
Exit Sub
End If
If Err.Number <> 0 Then
MsgBox "Unable to delete existing file. Please make sure the file is not open or write protected." _
& vbCrLf & vbCrLf & "Press OK to exit this macro.", vbCritical, "Unable to Delete File"
Exit Sub
End If
End If
Set xUsedRng = xSht.UsedRange
If Application.WorksheetFunction.CountA(xUsedRng.Cells) <> 0 Then
'Save as PDF file
xSht.ExportAsFixedFormat Type:=xlTypePDF, Filename:=xFolder, Quality:=xlQualityStandard
Else
MsgBox "The active worksheet cannot be blank"
Exit Sub
End If
End Sub
The spreadsheets looks correct on their screen when in Excel but change when exporting to PDF.
What could cause this and is there something I can do in my code?
Thanks in advance!