Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Here is a function I am attempting to use. It seemed to work fine until I attempted to account for the user hitting cancel when prompted to enter a file name. I get a type mismatch error because the cancel button returns a boolean instead of a string. How do I rectify this? Am I going about this all wrong? Any help is appreciated. Function SaveToPDF() As Boolean Dim folderName As String Dim fileName As String Dim namingError fileName = "" folderName = BrowseFolder(Caption:="Select A Folder", InitialFolder:="C:\Documents and Settings\Jamie\Desktop\") If folderName = "" Then Exit Function ' User hit Cancel Else While fileName = "" fileName = Application.InputBox("Enter a name for the PDF file.") If fileName = False Then SaveToPDF = False Exit Function 'user hit cancel Else If fileName = "" Then namingError = MsgBox("You must enter a name for the file or click Cancel to exit. Click OK to" _ + " return to the name entry screen", vbOKOnly, "File Naming Error") Else ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, fileName:= _ folderName + "\" + fileName + ".pdf", Quality:= _ xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _ OpenAfterPublish:=False SaveToPDF = True End If End If Wend End If Application.WindowState = xlNormal End Function |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Declare Dim fileName As Variant 'since it can be a string or a boolean. The Inspector wrote: Here is a function I am attempting to use. It seemed to work fine until I attempted to account for the user hitting cancel when prompted to enter a file name. I get a type mismatch error because the cancel button returns a boolean instead of a string. How do I rectify this? Am I going about this all wrong? Any help is appreciated. Function SaveToPDF() As Boolean Dim folderName As String Dim fileName As String Dim namingError fileName = "" folderName = BrowseFolder(Caption:="Select A Folder", InitialFolder:="C:\Documents and Settings\Jamie\Desktop\") If folderName = "" Then Exit Function ' User hit Cancel Else While fileName = "" fileName = Application.InputBox("Enter a name for the PDF file.") If fileName = False Then SaveToPDF = False Exit Function 'user hit cancel Else If fileName = "" Then namingError = MsgBox("You must enter a name for the file or click Cancel to exit. Click OK to" _ + " return to the name entry screen", vbOKOnly, "File Naming Error") Else ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, fileName:= _ folderName + "\" + fileName + ".pdf", Quality:= _ xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _ OpenAfterPublish:=False SaveToPDF = True End If End If Wend End If Application.WindowState = xlNormal End Function -- Dave Peterson |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Thanks. That did it. "Dave Peterson" wrote: Declare Dim fileName As Variant 'since it can be a string or a boolean. The Inspector wrote: Here is a function I am attempting to use. It seemed to work fine until I attempted to account for the user hitting cancel when prompted to enter a file name. I get a type mismatch error because the cancel button returns a boolean instead of a string. How do I rectify this? Am I going about this all wrong? Any help is appreciated. Function SaveToPDF() As Boolean Dim folderName As String Dim fileName As String Dim namingError fileName = "" folderName = BrowseFolder(Caption:="Select A Folder", InitialFolder:="C:\Documents and Settings\Jamie\Desktop\") If folderName = "" Then Exit Function ' User hit Cancel Else While fileName = "" fileName = Application.InputBox("Enter a name for the PDF file.") If fileName = False Then SaveToPDF = False Exit Function 'user hit cancel Else If fileName = "" Then namingError = MsgBox("You must enter a name for the file or click Cancel to exit. Click OK to" _ + " return to the name entry screen", vbOKOnly, "File Naming Error") Else ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, fileName:= _ folderName + "\" + fileName + ".pdf", Quality:= _ xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _ OpenAfterPublish:=False SaveToPDF = True End If End If Wend End If Application.WindowState = xlNormal End Function -- Dave Peterson |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() If folderName = "False" Then "The Inspector" wrote in message ... Here is a function I am attempting to use. It seemed to work fine until I attempted to account for the user hitting cancel when prompted to enter a file name. I get a type mismatch error because the cancel button returns a boolean instead of a string. How do I rectify this? Am I going about this all wrong? Any help is appreciated. Function SaveToPDF() As Boolean Dim folderName As String Dim fileName As String Dim namingError fileName = "" folderName = BrowseFolder(Caption:="Select A Folder", InitialFolder:="C:\Documents and Settings\Jamie\Desktop\") If folderName = "" Then Exit Function ' User hit Cancel Else While fileName = "" fileName = Application.InputBox("Enter a name for the PDF file.") If fileName = False Then SaveToPDF = False Exit Function 'user hit cancel Else If fileName = "" Then namingError = MsgBox("You must enter a name for the file or click Cancel to exit. Click OK to" _ + " return to the name entry screen", vbOKOnly, "File Naming Error") Else ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, fileName:= _ folderName + "\" + fileName + ".pdf", Quality:= _ xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _ OpenAfterPublish:=False SaveToPDF = True End If End If Wend End If Application.WindowState = xlNormal End Function |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
'Cancel' on User Prompt Box | Excel Programming | |||
how do i cancel user restricted values in a cell | New Users to Excel | |||
Halt / Stop processing when a user selects Cancel | Excel Programming | |||
Cancel Macro is user selects 'cancel' at save menu | Excel Programming | |||
Dialog Box - User hits cancel | Excel Programming |