Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default User hits Cancel


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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default User hits Cancel


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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default User hits Cancel


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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default User hits Cancel


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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
'Cancel' on User Prompt Box [email protected] Excel Programming 2 May 12th 09 02:12 AM
how do i cancel user restricted values in a cell grahamcotton New Users to Excel 1 August 14th 08 05:15 PM
Halt / Stop processing when a user selects Cancel scott56hannah Excel Programming 3 June 25th 08 12:55 PM
Cancel Macro is user selects 'cancel' at save menu Mark Excel Programming 1 April 6th 05 05:45 PM
Dialog Box - User hits cancel CS[_2_] Excel Programming 4 November 14th 03 10:05 PM


All times are GMT +1. The time now is 04:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"