Ok. I can't figure this out. I've stepped through the whole thing, and everything seems to look fine, but when it does finally save it saves to the folder immediately preceeding the folder I pick. Not sure why.
Here's the code for the SaveToPDF:
Public Sub PrintToPDF(control As IRibbonControl)
' used to easily save and name the selected sheet to a PDF
' depending on the active sheet and the information available on that sheet.
Dim folderPath As String
Dim newFileName As String
Dim currentLocationAndName As String
Dim fd As fileDialog
Dim sheetToPrint As Worksheet
Dim workbookName As String
Dim workbookPath As String
Dim refWS As Worksheet
Dim entityName As String
Const pdfExt = ".pdf"
currentLocationAndName = ThisWorkbook.FullName
If InStr(currentLocationAndName, "") = 0 Then
MsgBox "You must first save this file to disk before you can save as PDF", _
vbOKOnly + vbCritical, "File Not Save"
Exit Sub
End If
' create a new name for the pdf file
' would be based on active sheet name and type info
Set sheetToPrint = ThisWorkbook.activeSheet
' Grab the entity name from the Instructions sheet
Set refWS = ThisWorkbook.Worksheets(instructionSheetName)
entityName = refWS.Range(entityNameCell).Value
Set refWS = Nothing
' Create the path
newFileName = folderPath & entityName & " - "
' add the SELECT CASE structure here to find the relevant
' information for each sheet type
' add to the newFileName
Select Case sheetToPrint.Name
Case Is = dailyName
newFileName = newFileName & ReturnSingleDate(sheetToPrint) & pdfExt
Case Is = balanceSummary
newFileName = newFileName & ReturnSingleDate(sheetToPrint) & pdfExt
Case Is = balanceDetailed
newFileName = newFileName & ReturnSingleDate(sheetToPrint) & pdfExt
Case Is = periodSummaryName
newFileName = newFileName & ReturnSingleYear(sheetToPrint) & pdfExt
Case Is = periodBudgetName
newFileName = newFileName & ReturnSingleYear(sheetToPrint) & pdfExt
Case Is = investorName
newFileName = newFileName & ReturnSingleYear(sheetToPrint) & pdfExt
Case Is = budgetSheetName
newFileName = newFileName & ReturnSingleYear(sheetToPrint) & pdfExt
Case Is = eopSheetName
newFileName = newFileName & ReturnPeriodAndYear(sheetToPrint) & pdfExt
Case Is = midPeriodName
newFileName = newFileName & ReturnPeriodAndYear(sheetToPrint) & pdfExt
Case Is = plSheetName
newFileName = newFileName & ReturnSheetAndDateRange(sheetToPrint) & pdfExt
Case Is = weeklySheetName
newFileName = newFileName & ReturnSheetAndDateRange(sheetToPrint) & pdfExt
Case Else
' do nothing
End Select
' Test to see if the Microsoft Create/ Send Add-In is Installed
If Dir(Environ("commonprogramfiles") & "\Microsoft Shared\OFFICE" _
& Format(Val(Application.Version), "00") & "\EXP_PDF.DLL") <> "" Then
' Open the Folder Picker Dialog Box
folderPath = GetSaveToFolder()
If folderPath = "" Then
Exit Sub
End If
End If
' does the file already exist?
If Dir(newFileName) <> "" Then
If MsgBox("File: " & vbCrLf & newFileName & vbCrLf & _
"Already Exists. Overwrite it?", vbYesNoCancel + vbExclamation, _
"File Exists") <> vbYes Then
Exit Sub
End If
End If
On Error Resume Next
sheetToPrint.ExportAsFixedFormat Type:=xlTypePDF, _
fileName:=newFileName, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
If Err <> 0 Then
MsgBox "There was an unexpected error writing the .pdf file:" & vbCrLf _
& Err.Number & " " & Err.Description, vbOKOnly + vbCritical, "PDF Write Error"
Err.Clear
Else
MsgBox "File:" & vbCrLf & newFileName & vbCrLf & "Has been written.", _
vbOKOnly + vbInformation, "PDF File Successfully Written"
End If
On Error GoTo 0
End Sub