#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 177
Default Saving in Excel

Is there a way that when saving a excel file that i can get a name from a
cell or maybe two?

so if i had an invoice excel sheet that when you go to save it would take
the customers name and the invoice number and make that the file name.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,101
Default Saving in Excel

try this

Sub SaveWorkbookAs()
Dim CustomerName As String
Dim InvoiceNumber As String
'Change A1 to the cell your CustomerName is in
'Change B1 to the cell your InvoiceNumber is in
CustomerName = Range("A1").Value
InvoiceNumber = Range("B1").Value
Select Case MsgBox("Would you like to save this invoice", vbYesNo)

Case Is = vbYes
Application.ActiveWorkbook.SaveAs CustomerName & _
"_" & InvoiceNumber

Case Is = vbNo
Exit Sub
End Select
End Sub

"todd" wrote:

Is there a way that when saving a excel file that i can get a name from a
cell or maybe two?

so if i had an invoice excel sheet that when you go to save it would take
the customers name and the invoice number and make that the file name.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 177
Default Saving in Excel

Mike,

thanks for the help, the code works great.
can i get you to help me on one more thing?
Can i make it so that it will save in the dir that i want? it can be the
same one every time on a network drive.

"Mike" wrote:

try this

Sub SaveWorkbookAs()
Dim CustomerName As String
Dim InvoiceNumber As String
'Change A1 to the cell your CustomerName is in
'Change B1 to the cell your InvoiceNumber is in
CustomerName = Range("A1").Value
InvoiceNumber = Range("B1").Value
Select Case MsgBox("Would you like to save this invoice", vbYesNo)

Case Is = vbYes
Application.ActiveWorkbook.SaveAs CustomerName & _
"_" & InvoiceNumber

Case Is = vbNo
Exit Sub
End Select
End Sub

"todd" wrote:

Is there a way that when saving a excel file that i can get a name from a
cell or maybe two?

so if i had an invoice excel sheet that when you go to save it would take
the customers name and the invoice number and make that the file name.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,101
Default Saving in Excel

try this

Sub SaveWorkbookToFolder()
Dim CustomerName As String
Dim InvoiceNumber As String
Dim SaveToPath As String
Dim userInput As String
Dim anyFilename As String

'Change A1 to the cell your CustomerName is in
'Change B1 to the cell your InvoiceNumber is in
CustomerName = Range("A1").Value
InvoiceNumber = Range("B1").Value

'Change to the folder path need to be sure you have a \ at the end of path
SaveToPath = "\\Sever01\users\Invoices\SavedReports\"

anyFilename = CustomerName & _
"_" & InvoiceNumber & ".xls"

If Dir(SaveToPath & anyFilename) = "" Then

ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
Else

Select Case MsgBox("A file named: '" & anyFilename & " already
exists in " & SaveToPath _
& vbCrLf & "What would you like to do?" & vbCrLf _
& "Overwrite the existing file? [Yes]" & vbCrLf _
& "Save file with a different name? [No]" & vbCrLf _
& "Cancel - do not save this file at this time. [Cancel]", _
vbYesNoCancel + vbExclamation + vbDefaultButton2, "Save Invoice To
Folder")

Case Is = vbYes

Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
Application.DisplayAlerts = True

Case Is = vbNo


userInput = "dummy entry to make it work"

GetFileNameFromUser:
Do While userInput < ""
anyFilename = InputBox$("Enter a new filename to use:", _
"Commission Manager", CustomerName & _
"_" & InvoiceNumber)
If Right(UCase(Trim(anyFilename)), 4) < ".XLS" Then
anyFilename = anyFilename & ".xls"
End If
If ValidateFilename(anyFilename) < "" Then

MsgBox "The filename you have entered is not a valid
filename." _
& vbCrLf & "Filenames may not have any of these
characters in them:" _
& vbCrLf & " \ / : * ? < | " & Chr$(34) & vbCrLf _
& "Please provide a valid filename.", vbOKOnly,
"Invalid Filename"
GoTo GetFileNameFromUser
End If
If Trim(UCase(anyFilename)) = ".XLS" Then

If MsgBox("You have chosen to Cancel the file save." & _
"Did you really intend to Cancel this operation?", _
vbYesNo + vbInformation, "Confirm Cancel") < vbYes Then
GoTo GetFileNameFromUser
Else

anyFilename = ":* QUIT *:"
userInput = ""
End If
End If
If userInput < "" Then

userInput = Dir(SaveToPath & anyFilename)
End If
Loop


If anyFilename < ":* QUIT *:" Then

ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
End If

Case Else


Application.DisplayAlerts = False
ActiveWindow.Close
Application.DisplayAlerts = True

End Select
End If



End Sub



Private Function ValidateFilename(anyFilename As String) As String

Dim InvalidCharacterList As String
InvalidCharacterList = "\/:*?<|" & Chr$(34)
Dim LC As Integer

ValidateFilename = ""
If Len(Trim(anyFilename)) = 0 Then
ValidateFilename = "EMPTY"
Exit Function
End If
anyFilename = Trim(anyFilename)
For LC = 1 To Len(anyFilename)
If InStr(InvalidCharacterList, Mid(anyFilename, LC, 1)) Then
ValidateFilename = Mid(anyFilename, LC, 1)
Exit Function
End If
Next

End Function


"todd" wrote:

Mike,

thanks for the help, the code works great.
can i get you to help me on one more thing?
Can i make it so that it will save in the dir that i want? it can be the
same one every time on a network drive.

"Mike" wrote:

try this

Sub SaveWorkbookAs()
Dim CustomerName As String
Dim InvoiceNumber As String
'Change A1 to the cell your CustomerName is in
'Change B1 to the cell your InvoiceNumber is in
CustomerName = Range("A1").Value
InvoiceNumber = Range("B1").Value
Select Case MsgBox("Would you like to save this invoice", vbYesNo)

Case Is = vbYes
Application.ActiveWorkbook.SaveAs CustomerName & _
"_" & InvoiceNumber

Case Is = vbNo
Exit Sub
End Select
End Sub

"todd" wrote:

Is there a way that when saving a excel file that i can get a name from a
cell or maybe two?

so if i had an invoice excel sheet that when you go to save it would take
the customers name and the invoice number and make that the file name.

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 30
Default Saving in Excel


I am trying to accomplish the same thing. When I run this I get an error
message. can you verify that the code is error free? Thanks

Steve


"Mike" wrote:

try this

Sub SaveWorkbookToFolder()
Dim CustomerName As String
Dim InvoiceNumber As String
Dim SaveToPath As String
Dim userInput As String
Dim anyFilename As String

'Change A1 to the cell your CustomerName is in
'Change B1 to the cell your InvoiceNumber is in
CustomerName = Range("A1").Value
InvoiceNumber = Range("B1").Value

'Change to the folder path need to be sure you have a \ at the end of path
SaveToPath = "\\Sever01\users\Invoices\SavedReports\"

anyFilename = CustomerName & _
"_" & InvoiceNumber & ".xls"

If Dir(SaveToPath & anyFilename) = "" Then

ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
Else

Select Case MsgBox("A file named: '" & anyFilename & " already
exists in " & SaveToPath _
& vbCrLf & "What would you like to do?" & vbCrLf _
& "Overwrite the existing file? [Yes]" & vbCrLf _
& "Save file with a different name? [No]" & vbCrLf _
& "Cancel - do not save this file at this time. [Cancel]", _
vbYesNoCancel + vbExclamation + vbDefaultButton2, "Save Invoice To
Folder")

Case Is = vbYes

Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
Application.DisplayAlerts = True

Case Is = vbNo


userInput = "dummy entry to make it work"

GetFileNameFromUser:
Do While userInput < ""
anyFilename = InputBox$("Enter a new filename to use:", _
"Commission Manager", CustomerName & _
"_" & InvoiceNumber)
If Right(UCase(Trim(anyFilename)), 4) < ".XLS" Then
anyFilename = anyFilename & ".xls"
End If
If ValidateFilename(anyFilename) < "" Then

MsgBox "The filename you have entered is not a valid
filename." _
& vbCrLf & "Filenames may not have any of these
characters in them:" _
& vbCrLf & " \ / : * ? < | " & Chr$(34) & vbCrLf _
& "Please provide a valid filename.", vbOKOnly,
"Invalid Filename"
GoTo GetFileNameFromUser
End If
If Trim(UCase(anyFilename)) = ".XLS" Then

If MsgBox("You have chosen to Cancel the file save." & _
"Did you really intend to Cancel this operation?", _
vbYesNo + vbInformation, "Confirm Cancel") < vbYes Then
GoTo GetFileNameFromUser
Else

anyFilename = ":* QUIT *:"
userInput = ""
End If
End If
If userInput < "" Then

userInput = Dir(SaveToPath & anyFilename)
End If
Loop


If anyFilename < ":* QUIT *:" Then

ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
End If

Case Else


Application.DisplayAlerts = False
ActiveWindow.Close
Application.DisplayAlerts = True

End Select
End If



End Sub



Private Function ValidateFilename(anyFilename As String) As String

Dim InvalidCharacterList As String
InvalidCharacterList = "\/:*?<|" & Chr$(34)
Dim LC As Integer

ValidateFilename = ""
If Len(Trim(anyFilename)) = 0 Then
ValidateFilename = "EMPTY"
Exit Function
End If
anyFilename = Trim(anyFilename)
For LC = 1 To Len(anyFilename)
If InStr(InvalidCharacterList, Mid(anyFilename, LC, 1)) Then
ValidateFilename = Mid(anyFilename, LC, 1)
Exit Function
End If
Next

End Function


"todd" wrote:

Mike,

thanks for the help, the code works great.
can i get you to help me on one more thing?
Can i make it so that it will save in the dir that i want? it can be the
same one every time on a network drive.

"Mike" wrote:

try this

Sub SaveWorkbookAs()
Dim CustomerName As String
Dim InvoiceNumber As String
'Change A1 to the cell your CustomerName is in
'Change B1 to the cell your InvoiceNumber is in
CustomerName = Range("A1").Value
InvoiceNumber = Range("B1").Value
Select Case MsgBox("Would you like to save this invoice", vbYesNo)

Case Is = vbYes
Application.ActiveWorkbook.SaveAs CustomerName & _
"_" & InvoiceNumber

Case Is = vbNo
Exit Sub
End Select
End Sub

"todd" wrote:

Is there a way that when saving a excel file that i can get a name from a
cell or maybe two?

so if i had an invoice excel sheet that when you go to save it would take
the customers name and the invoice number and make that the file name.



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 30
Default Saving in Excel

This is the section I am getting a syntax error

Select Case MsgBox("A file named: '" & anyFilename & " already
exists in " & SaveToPath _
& vbCrLf & "What would you like to do?" & vbCrLf _
& "Overwrite the existing file? [Yes]" & vbCrLf _
& "Save file with a different name? [No]" & vbCrLf _
& "Cancel - do not save this file at this time. [Cancel]", _
vbYesNoCancel + vbExclamation + vbDefaultButton2, "Save Invoice To
Folder ")"


Thanks

"Mike" wrote:

try this

Sub SaveWorkbookToFolder()
Dim CustomerName As String
Dim InvoiceNumber As String
Dim SaveToPath As String
Dim userInput As String
Dim anyFilename As String

'Change A1 to the cell your CustomerName is in
'Change B1 to the cell your InvoiceNumber is in
CustomerName = Range("A1").Value
InvoiceNumber = Range("B1").Value

'Change to the folder path need to be sure you have a \ at the end of path
SaveToPath = "\\Sever01\users\Invoices\SavedReports\"

anyFilename = CustomerName & _
"_" & InvoiceNumber & ".xls"

If Dir(SaveToPath & anyFilename) = "" Then

ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
Else

Select Case MsgBox("A file named: '" & anyFilename & " already
exists in " & SaveToPath _
& vbCrLf & "What would you like to do?" & vbCrLf _
& "Overwrite the existing file? [Yes]" & vbCrLf _
& "Save file with a different name? [No]" & vbCrLf _
& "Cancel - do not save this file at this time. [Cancel]", _
vbYesNoCancel + vbExclamation + vbDefaultButton2, "Save Invoice To
Folder")

Case Is = vbYes

Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
Application.DisplayAlerts = True

Case Is = vbNo


userInput = "dummy entry to make it work"

GetFileNameFromUser:
Do While userInput < ""
anyFilename = InputBox$("Enter a new filename to use:", _
"Commission Manager", CustomerName & _
"_" & InvoiceNumber)
If Right(UCase(Trim(anyFilename)), 4) < ".XLS" Then
anyFilename = anyFilename & ".xls"
End If
If ValidateFilename(anyFilename) < "" Then

MsgBox "The filename you have entered is not a valid
filename." _
& vbCrLf & "Filenames may not have any of these
characters in them:" _
& vbCrLf & " \ / : * ? < | " & Chr$(34) & vbCrLf _
& "Please provide a valid filename.", vbOKOnly,
"Invalid Filename"
GoTo GetFileNameFromUser
End If
If Trim(UCase(anyFilename)) = ".XLS" Then

If MsgBox("You have chosen to Cancel the file save." & _
"Did you really intend to Cancel this operation?", _
vbYesNo + vbInformation, "Confirm Cancel") < vbYes Then
GoTo GetFileNameFromUser
Else

anyFilename = ":* QUIT *:"
userInput = ""
End If
End If
If userInput < "" Then

userInput = Dir(SaveToPath & anyFilename)
End If
Loop


If anyFilename < ":* QUIT *:" Then

ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
End If

Case Else


Application.DisplayAlerts = False
ActiveWindow.Close
Application.DisplayAlerts = True

End Select
End If



End Sub



Private Function ValidateFilename(anyFilename As String) As String

Dim InvalidCharacterList As String
InvalidCharacterList = "\/:*?<|" & Chr$(34)
Dim LC As Integer

ValidateFilename = ""
If Len(Trim(anyFilename)) = 0 Then
ValidateFilename = "EMPTY"
Exit Function
End If
anyFilename = Trim(anyFilename)
For LC = 1 To Len(anyFilename)
If InStr(InvalidCharacterList, Mid(anyFilename, LC, 1)) Then
ValidateFilename = Mid(anyFilename, LC, 1)
Exit Function
End If
Next

End Function


"todd" wrote:

Mike,

thanks for the help, the code works great.
can i get you to help me on one more thing?
Can i make it so that it will save in the dir that i want? it can be the
same one every time on a network drive.

"Mike" wrote:

try this

Sub SaveWorkbookAs()
Dim CustomerName As String
Dim InvoiceNumber As String
'Change A1 to the cell your CustomerName is in
'Change B1 to the cell your InvoiceNumber is in
CustomerName = Range("A1").Value
InvoiceNumber = Range("B1").Value
Select Case MsgBox("Would you like to save this invoice", vbYesNo)

Case Is = vbYes
Application.ActiveWorkbook.SaveAs CustomerName & _
"_" & InvoiceNumber

Case Is = vbNo
Exit Sub
End Select
End Sub

"todd" wrote:

Is there a way that when saving a excel file that i can get a name from a
cell or maybe two?

so if i had an invoice excel sheet that when you go to save it would take
the customers name and the invoice number and make that the file name.

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,101
Default Saving in Excel

What error are getting and could you post your code to look at

"S Willingham" wrote:


I am trying to accomplish the same thing. When I run this I get an error
message. can you verify that the code is error free? Thanks

Steve


"Mike" wrote:

try this

Sub SaveWorkbookToFolder()
Dim CustomerName As String
Dim InvoiceNumber As String
Dim SaveToPath As String
Dim userInput As String
Dim anyFilename As String

'Change A1 to the cell your CustomerName is in
'Change B1 to the cell your InvoiceNumber is in
CustomerName = Range("A1").Value
InvoiceNumber = Range("B1").Value

'Change to the folder path need to be sure you have a \ at the end of path
SaveToPath = "\\Sever01\users\Invoices\SavedReports\"

anyFilename = CustomerName & _
"_" & InvoiceNumber & ".xls"

If Dir(SaveToPath & anyFilename) = "" Then

ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
Else

Select Case MsgBox("A file named: '" & anyFilename & " already
exists in " & SaveToPath _
& vbCrLf & "What would you like to do?" & vbCrLf _
& "Overwrite the existing file? [Yes]" & vbCrLf _
& "Save file with a different name? [No]" & vbCrLf _
& "Cancel - do not save this file at this time. [Cancel]", _
vbYesNoCancel + vbExclamation + vbDefaultButton2, "Save Invoice To
Folder")

Case Is = vbYes

Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
Application.DisplayAlerts = True

Case Is = vbNo


userInput = "dummy entry to make it work"

GetFileNameFromUser:
Do While userInput < ""
anyFilename = InputBox$("Enter a new filename to use:", _
"Commission Manager", CustomerName & _
"_" & InvoiceNumber)
If Right(UCase(Trim(anyFilename)), 4) < ".XLS" Then
anyFilename = anyFilename & ".xls"
End If
If ValidateFilename(anyFilename) < "" Then

MsgBox "The filename you have entered is not a valid
filename." _
& vbCrLf & "Filenames may not have any of these
characters in them:" _
& vbCrLf & " \ / : * ? < | " & Chr$(34) & vbCrLf _
& "Please provide a valid filename.", vbOKOnly,
"Invalid Filename"
GoTo GetFileNameFromUser
End If
If Trim(UCase(anyFilename)) = ".XLS" Then

If MsgBox("You have chosen to Cancel the file save." & _
"Did you really intend to Cancel this operation?", _
vbYesNo + vbInformation, "Confirm Cancel") < vbYes Then
GoTo GetFileNameFromUser
Else

anyFilename = ":* QUIT *:"
userInput = ""
End If
End If
If userInput < "" Then

userInput = Dir(SaveToPath & anyFilename)
End If
Loop


If anyFilename < ":* QUIT *:" Then

ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
End If

Case Else


Application.DisplayAlerts = False
ActiveWindow.Close
Application.DisplayAlerts = True

End Select
End If



End Sub



Private Function ValidateFilename(anyFilename As String) As String

Dim InvalidCharacterList As String
InvalidCharacterList = "\/:*?<|" & Chr$(34)
Dim LC As Integer

ValidateFilename = ""
If Len(Trim(anyFilename)) = 0 Then
ValidateFilename = "EMPTY"
Exit Function
End If
anyFilename = Trim(anyFilename)
For LC = 1 To Len(anyFilename)
If InStr(InvalidCharacterList, Mid(anyFilename, LC, 1)) Then
ValidateFilename = Mid(anyFilename, LC, 1)
Exit Function
End If
Next

End Function


"todd" wrote:

Mike,

thanks for the help, the code works great.
can i get you to help me on one more thing?
Can i make it so that it will save in the dir that i want? it can be the
same one every time on a network drive.

"Mike" wrote:

try this

Sub SaveWorkbookAs()
Dim CustomerName As String
Dim InvoiceNumber As String
'Change A1 to the cell your CustomerName is in
'Change B1 to the cell your InvoiceNumber is in
CustomerName = Range("A1").Value
InvoiceNumber = Range("B1").Value
Select Case MsgBox("Would you like to save this invoice", vbYesNo)

Case Is = vbYes
Application.ActiveWorkbook.SaveAs CustomerName & _
"_" & InvoiceNumber

Case Is = vbNo
Exit Sub
End Select
End Sub

"todd" wrote:

Is there a way that when saving a excel file that i can get a name from a
cell or maybe two?

so if i had an invoice excel sheet that when you go to save it would take
the customers name and the invoice number and make that the file name.

  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,101
Default Saving in Excel

mayby this will work


Sub SaveWorkbookToFolder()
Dim CustomerName As String
Dim InvoiceNumber As String
Dim SaveToPath As String
Dim userInput As String
Dim anyFilename As String

'Change A1 to the cell your CustomerName is in
'Change B1 to the cell your InvoiceNumber is in
CustomerName = Range("A1").Value
InvoiceNumber = Range("B1").Value

'Change to the folder path need to be sure you have a \ at the end of path
SaveToPath = "\\Sever01\users\Invoices\SavedReports\"

anyFilename = CustomerName & _
"_" & InvoiceNumber & ".xls"

If Dir(SaveToPath & anyFilename) = "" Then

ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
Else

Select Case MsgBox _
("A file named: '" & anyFilename & " already exists in " & SaveToPath _
& vbCrLf & "What would you like to do?" & vbCrLf _
& "Overwrite the existing file? [Yes]" & vbCrLf _
& "Save file with a different name? [No]" & vbCrLf _
& "Cancel - do not save this file at this time. [Cancel]", _
vbYesNoCancel + vbExclamation + vbDefaultButton2, "Save Invoice To Folder ")

Case Is = vbYes

Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
Application.DisplayAlerts = True

Case Is = vbNo


userInput = "dummy entry to make it work"

GetFileNameFromUser:
Do While userInput < ""
anyFilename = InputBox$("Enter a new filename to use:", _
"Commission Manager", CustomerName & _
"_" & InvoiceNumber)
If Right(UCase(Trim(anyFilename)), 4) < ".XLS" Then
anyFilename = anyFilename & ".xls"
End If
If ValidateFilename(anyFilename) < "" Then

MsgBox _
"The filename you have entered is not a valid filename." _
& vbCrLf & _
"Filenames may not have any of these characters in them:" _
& vbCrLf & _
" \ / : * ? < | " & Chr$(34) & vbCrLf _
& "Please provide a valid filename.", _
vbOKOnly, "Invalid Filename"
GoTo GetFileNameFromUser
End If
If Trim(UCase(anyFilename)) = ".XLS" Then

If MsgBox("You have chosen to Cancel the file save." & _
"Did you really intend to Cancel this operation?", _
vbYesNo + vbInformation, "Confirm Cancel") < vbYes Then
GoTo GetFileNameFromUser
Else

anyFilename = ":* QUIT *:"
userInput = ""
End If
End If
If userInput < "" Then

userInput = Dir(SaveToPath & anyFilename)
End If
Loop


If anyFilename < ":* QUIT *:" Then

ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
End If

Case Else


Application.DisplayAlerts = False
ActiveWindow.Close
Application.DisplayAlerts = True

End Select
End If



End Sub



Private Function ValidateFilename(anyFilename As String) As String

Dim InvalidCharacterList As String
InvalidCharacterList = "\/:*?<|" & Chr$(34)
Dim LC As Integer

ValidateFilename = ""
If Len(Trim(anyFilename)) = 0 Then
ValidateFilename = "EMPTY"
Exit Function
End If
anyFilename = Trim(anyFilename)
For LC = 1 To Len(anyFilename)
If InStr(InvalidCharacterList, Mid(anyFilename, LC, 1)) Then
ValidateFilename = Mid(anyFilename, LC, 1)
Exit Function
End If
Next

End Function

"S Willingham" wrote:


I am trying to accomplish the same thing. When I run this I get an error
message. can you verify that the code is error free? Thanks

Steve


"Mike" wrote:

try this

Sub SaveWorkbookToFolder()
Dim CustomerName As String
Dim InvoiceNumber As String
Dim SaveToPath As String
Dim userInput As String
Dim anyFilename As String

'Change A1 to the cell your CustomerName is in
'Change B1 to the cell your InvoiceNumber is in
CustomerName = Range("A1").Value
InvoiceNumber = Range("B1").Value

'Change to the folder path need to be sure you have a \ at the end of path
SaveToPath = "\\Sever01\users\Invoices\SavedReports\"

anyFilename = CustomerName & _
"_" & InvoiceNumber & ".xls"

If Dir(SaveToPath & anyFilename) = "" Then

ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
Else

Select Case MsgBox("A file named: '" & anyFilename & " already
exists in " & SaveToPath _
& vbCrLf & "What would you like to do?" & vbCrLf _
& "Overwrite the existing file? [Yes]" & vbCrLf _
& "Save file with a different name? [No]" & vbCrLf _
& "Cancel - do not save this file at this time. [Cancel]", _
vbYesNoCancel + vbExclamation + vbDefaultButton2, "Save Invoice To
Folder")

Case Is = vbYes

Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
Application.DisplayAlerts = True

Case Is = vbNo


userInput = "dummy entry to make it work"

GetFileNameFromUser:
Do While userInput < ""
anyFilename = InputBox$("Enter a new filename to use:", _
"Commission Manager", CustomerName & _
"_" & InvoiceNumber)
If Right(UCase(Trim(anyFilename)), 4) < ".XLS" Then
anyFilename = anyFilename & ".xls"
End If
If ValidateFilename(anyFilename) < "" Then

MsgBox "The filename you have entered is not a valid
filename." _
& vbCrLf & "Filenames may not have any of these
characters in them:" _
& vbCrLf & " \ / : * ? < | " & Chr$(34) & vbCrLf _
& "Please provide a valid filename.", vbOKOnly,
"Invalid Filename"
GoTo GetFileNameFromUser
End If
If Trim(UCase(anyFilename)) = ".XLS" Then

If MsgBox("You have chosen to Cancel the file save." & _
"Did you really intend to Cancel this operation?", _
vbYesNo + vbInformation, "Confirm Cancel") < vbYes Then
GoTo GetFileNameFromUser
Else

anyFilename = ":* QUIT *:"
userInput = ""
End If
End If
If userInput < "" Then

userInput = Dir(SaveToPath & anyFilename)
End If
Loop


If anyFilename < ":* QUIT *:" Then

ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
End If

Case Else


Application.DisplayAlerts = False
ActiveWindow.Close
Application.DisplayAlerts = True

End Select
End If



End Sub



Private Function ValidateFilename(anyFilename As String) As String

Dim InvalidCharacterList As String
InvalidCharacterList = "\/:*?<|" & Chr$(34)
Dim LC As Integer

ValidateFilename = ""
If Len(Trim(anyFilename)) = 0 Then
ValidateFilename = "EMPTY"
Exit Function
End If
anyFilename = Trim(anyFilename)
For LC = 1 To Len(anyFilename)
If InStr(InvalidCharacterList, Mid(anyFilename, LC, 1)) Then
ValidateFilename = Mid(anyFilename, LC, 1)
Exit Function
End If
Next

End Function


"todd" wrote:

Mike,

thanks for the help, the code works great.
can i get you to help me on one more thing?
Can i make it so that it will save in the dir that i want? it can be the
same one every time on a network drive.

"Mike" wrote:

try this

Sub SaveWorkbookAs()
Dim CustomerName As String
Dim InvoiceNumber As String
'Change A1 to the cell your CustomerName is in
'Change B1 to the cell your InvoiceNumber is in
CustomerName = Range("A1").Value
InvoiceNumber = Range("B1").Value
Select Case MsgBox("Would you like to save this invoice", vbYesNo)

Case Is = vbYes
Application.ActiveWorkbook.SaveAs CustomerName & _
"_" & InvoiceNumber

Case Is = vbNo
Exit Sub
End Select
End Sub

"todd" wrote:

Is there a way that when saving a excel file that i can get a name from a
cell or maybe two?

so if i had an invoice excel sheet that when you go to save it would take
the customers name and the invoice number and make that the file name.

  #9   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 30
Default Saving in Excel


Now I am getting an error on this line

If Dir(SaveToPath & anyFilename) = "" Then


Thanks
"S Willingham" wrote:

This is the section I am getting a syntax error

Select Case MsgBox("A file named: '" & anyFilename & " already
exists in " & SaveToPath _
& vbCrLf & "What would you like to do?" & vbCrLf _
& "Overwrite the existing file? [Yes]" & vbCrLf _
& "Save file with a different name? [No]" & vbCrLf _
& "Cancel - do not save this file at this time. [Cancel]", _
vbYesNoCancel + vbExclamation + vbDefaultButton2, "Save Invoice To
Folder ")"


Thanks

"Mike" wrote:

try this

Sub SaveWorkbookToFolder()
Dim CustomerName As String
Dim InvoiceNumber As String
Dim SaveToPath As String
Dim userInput As String
Dim anyFilename As String

'Change A1 to the cell your CustomerName is in
'Change B1 to the cell your InvoiceNumber is in
CustomerName = Range("A1").Value
InvoiceNumber = Range("B1").Value

'Change to the folder path need to be sure you have a \ at the end of path
SaveToPath = "\\Sever01\users\Invoices\SavedReports\"

anyFilename = CustomerName & _
"_" & InvoiceNumber & ".xls"

If Dir(SaveToPath & anyFilename) = "" Then

ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
Else

Select Case MsgBox("A file named: '" & anyFilename & " already
exists in " & SaveToPath _
& vbCrLf & "What would you like to do?" & vbCrLf _
& "Overwrite the existing file? [Yes]" & vbCrLf _
& "Save file with a different name? [No]" & vbCrLf _
& "Cancel - do not save this file at this time. [Cancel]", _
vbYesNoCancel + vbExclamation + vbDefaultButton2, "Save Invoice To
Folder")

Case Is = vbYes

Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
Application.DisplayAlerts = True

Case Is = vbNo


userInput = "dummy entry to make it work"

GetFileNameFromUser:
Do While userInput < ""
anyFilename = InputBox$("Enter a new filename to use:", _
"Commission Manager", CustomerName & _
"_" & InvoiceNumber)
If Right(UCase(Trim(anyFilename)), 4) < ".XLS" Then
anyFilename = anyFilename & ".xls"
End If
If ValidateFilename(anyFilename) < "" Then

MsgBox "The filename you have entered is not a valid
filename." _
& vbCrLf & "Filenames may not have any of these
characters in them:" _
& vbCrLf & " \ / : * ? < | " & Chr$(34) & vbCrLf _
& "Please provide a valid filename.", vbOKOnly,
"Invalid Filename"
GoTo GetFileNameFromUser
End If
If Trim(UCase(anyFilename)) = ".XLS" Then

If MsgBox("You have chosen to Cancel the file save." & _
"Did you really intend to Cancel this operation?", _
vbYesNo + vbInformation, "Confirm Cancel") < vbYes Then
GoTo GetFileNameFromUser
Else

anyFilename = ":* QUIT *:"
userInput = ""
End If
End If
If userInput < "" Then

userInput = Dir(SaveToPath & anyFilename)
End If
Loop


If anyFilename < ":* QUIT *:" Then

ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
End If

Case Else


Application.DisplayAlerts = False
ActiveWindow.Close
Application.DisplayAlerts = True

End Select
End If



End Sub



Private Function ValidateFilename(anyFilename As String) As String

Dim InvalidCharacterList As String
InvalidCharacterList = "\/:*?<|" & Chr$(34)
Dim LC As Integer

ValidateFilename = ""
If Len(Trim(anyFilename)) = 0 Then
ValidateFilename = "EMPTY"
Exit Function
End If
anyFilename = Trim(anyFilename)
For LC = 1 To Len(anyFilename)
If InStr(InvalidCharacterList, Mid(anyFilename, LC, 1)) Then
ValidateFilename = Mid(anyFilename, LC, 1)
Exit Function
End If
Next

End Function


"todd" wrote:

Mike,

thanks for the help, the code works great.
can i get you to help me on one more thing?
Can i make it so that it will save in the dir that i want? it can be the
same one every time on a network drive.

"Mike" wrote:

try this

Sub SaveWorkbookAs()
Dim CustomerName As String
Dim InvoiceNumber As String
'Change A1 to the cell your CustomerName is in
'Change B1 to the cell your InvoiceNumber is in
CustomerName = Range("A1").Value
InvoiceNumber = Range("B1").Value
Select Case MsgBox("Would you like to save this invoice", vbYesNo)

Case Is = vbYes
Application.ActiveWorkbook.SaveAs CustomerName & _
"_" & InvoiceNumber

Case Is = vbNo
Exit Sub
End Select
End Sub

"todd" wrote:

Is there a way that when saving a excel file that i can get a name from a
cell or maybe two?

so if i had an invoice excel sheet that when you go to save it would take
the customers name and the invoice number and make that the file name.

  #10   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,101
Default Saving in Excel

Post the whole code that you are using

"S Willingham" wrote:


Now I am getting an error on this line

If Dir(SaveToPath & anyFilename) = "" Then


Thanks
"S Willingham" wrote:

This is the section I am getting a syntax error

Select Case MsgBox("A file named: '" & anyFilename & " already
exists in " & SaveToPath _
& vbCrLf & "What would you like to do?" & vbCrLf _
& "Overwrite the existing file? [Yes]" & vbCrLf _
& "Save file with a different name? [No]" & vbCrLf _
& "Cancel - do not save this file at this time. [Cancel]", _
vbYesNoCancel + vbExclamation + vbDefaultButton2, "Save Invoice To
Folder ")"


Thanks

"Mike" wrote:

try this

Sub SaveWorkbookToFolder()
Dim CustomerName As String
Dim InvoiceNumber As String
Dim SaveToPath As String
Dim userInput As String
Dim anyFilename As String

'Change A1 to the cell your CustomerName is in
'Change B1 to the cell your InvoiceNumber is in
CustomerName = Range("A1").Value
InvoiceNumber = Range("B1").Value

'Change to the folder path need to be sure you have a \ at the end of path
SaveToPath = "\\Sever01\users\Invoices\SavedReports\"

anyFilename = CustomerName & _
"_" & InvoiceNumber & ".xls"

If Dir(SaveToPath & anyFilename) = "" Then

ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
Else

Select Case MsgBox("A file named: '" & anyFilename & " already
exists in " & SaveToPath _
& vbCrLf & "What would you like to do?" & vbCrLf _
& "Overwrite the existing file? [Yes]" & vbCrLf _
& "Save file with a different name? [No]" & vbCrLf _
& "Cancel - do not save this file at this time. [Cancel]", _
vbYesNoCancel + vbExclamation + vbDefaultButton2, "Save Invoice To
Folder")

Case Is = vbYes

Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
Application.DisplayAlerts = True

Case Is = vbNo


userInput = "dummy entry to make it work"

GetFileNameFromUser:
Do While userInput < ""
anyFilename = InputBox$("Enter a new filename to use:", _
"Commission Manager", CustomerName & _
"_" & InvoiceNumber)
If Right(UCase(Trim(anyFilename)), 4) < ".XLS" Then
anyFilename = anyFilename & ".xls"
End If
If ValidateFilename(anyFilename) < "" Then

MsgBox "The filename you have entered is not a valid
filename." _
& vbCrLf & "Filenames may not have any of these
characters in them:" _
& vbCrLf & " \ / : * ? < | " & Chr$(34) & vbCrLf _
& "Please provide a valid filename.", vbOKOnly,
"Invalid Filename"
GoTo GetFileNameFromUser
End If
If Trim(UCase(anyFilename)) = ".XLS" Then

If MsgBox("You have chosen to Cancel the file save." & _
"Did you really intend to Cancel this operation?", _
vbYesNo + vbInformation, "Confirm Cancel") < vbYes Then
GoTo GetFileNameFromUser
Else

anyFilename = ":* QUIT *:"
userInput = ""
End If
End If
If userInput < "" Then

userInput = Dir(SaveToPath & anyFilename)
End If
Loop


If anyFilename < ":* QUIT *:" Then

ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
End If

Case Else


Application.DisplayAlerts = False
ActiveWindow.Close
Application.DisplayAlerts = True

End Select
End If



End Sub



Private Function ValidateFilename(anyFilename As String) As String

Dim InvalidCharacterList As String
InvalidCharacterList = "\/:*?<|" & Chr$(34)
Dim LC As Integer

ValidateFilename = ""
If Len(Trim(anyFilename)) = 0 Then
ValidateFilename = "EMPTY"
Exit Function
End If
anyFilename = Trim(anyFilename)
For LC = 1 To Len(anyFilename)
If InStr(InvalidCharacterList, Mid(anyFilename, LC, 1)) Then
ValidateFilename = Mid(anyFilename, LC, 1)
Exit Function
End If
Next

End Function


"todd" wrote:

Mike,

thanks for the help, the code works great.
can i get you to help me on one more thing?
Can i make it so that it will save in the dir that i want? it can be the
same one every time on a network drive.

"Mike" wrote:

try this

Sub SaveWorkbookAs()
Dim CustomerName As String
Dim InvoiceNumber As String
'Change A1 to the cell your CustomerName is in
'Change B1 to the cell your InvoiceNumber is in
CustomerName = Range("A1").Value
InvoiceNumber = Range("B1").Value
Select Case MsgBox("Would you like to save this invoice", vbYesNo)

Case Is = vbYes
Application.ActiveWorkbook.SaveAs CustomerName & _
"_" & InvoiceNumber

Case Is = vbNo
Exit Sub
End Select
End Sub

"todd" wrote:

Is there a way that when saving a excel file that i can get a name from a
cell or maybe two?

so if i had an invoice excel sheet that when you go to save it would take
the customers name and the invoice number and make that the file name.



  #11   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 30
Default Saving in Excel


This is the code I'm using

Sub SaveWorkbookToFolder()
Dim CustomerName As String
Dim InvoiceNumber As String
Dim SaveToPath As String
Dim userInput As String
Dim anyFilename As String

'Change A1 to the cell your QuoteName is in
'Change B1 to the cell your CustomerName is in
QuoteName = Range("E8").Value
CustomerName = Range("B6").Value

'Change to the folder path need to be sure you have a \ at the end of path
SaveToPath = "\\C:\Documents and Settings\FaroTemplate\Desktop\Quotes\"

anyFilename = QuoteName & _
"_" & CustomerName & ".xls"

If Dir(SaveToPath & anyFilename) = "" Then

ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
Else

Select Case MsgBox _
("A file named: '" & anyFilename & " already exists in " & SaveToPath _
& vbCrLf & "What would you like to do?" & vbCrLf _
& "Overwrite the existing file? [Yes]" & vbCrLf _
& "Save file with a different name? [No]" & vbCrLf _
& "Cancel - do not save this file at this time. [Cancel]", _
vbYesNoCancel + vbExclamation + vbDefaultButton2, "Save Invoice To Folder ")

Case Is = vbYes

Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
Application.DisplayAlerts = True

Case Is = vbNo


userInput = "dummy entry to make it work"

GetFileNameFromUser:
Do While userInput < ""
anyFilename = InputBox$("Enter a new filename to use:", _
"Commission Manager", CustomerName & _
"_" & InvoiceNumber)
If Right(UCase(Trim(anyFilename)), 4) < ".XLS" Then
anyFilename = anyFilename & ".xls"
End If
If ValidateFilename(anyFilename) < "" Then

MsgBox _
"The filename you have entered is not a valid filename." _
& vbCrLf & _
"Filenames may not have any of these characters in them:" _
& vbCrLf & _
" \ / : * ? < | " & Chr$(34) & vbCrLf _
& "Please provide a valid filename.", _
vbOKOnly, "Invalid Filename"
GoTo GetFileNameFromUser
End If
If Trim(UCase(anyFilename)) = ".XLS" Then

If MsgBox("You have chosen to Cancel the file save." & _
"Did you really intend to Cancel this operation?", _
vbYesNo + vbInformation, "Confirm Cancel") < vbYes Then
GoTo GetFileNameFromUser
Else

anyFilename = ":* QUIT *:"
userInput = ""
End If
End If
If userInput < "" Then

userInput = Dir(SaveToPath & anyFilename)
End If
Loop


If anyFilename < ":* QUIT *:" Then

ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
End If

Case Else


Application.DisplayAlerts = False
ActiveWindow.Close
Application.DisplayAlerts = True

End Select
End If

End Sub



Private Function ValidateFilename(anyFilename As String) As String

Dim InvalidCharacterList As String
InvalidCharacterList = "\/:*?<|" & Chr$(34)
Dim LC As Integer

ValidateFilename = ""
If Len(Trim(anyFilename)) = 0 Then
ValidateFilename = "EMPTY"
Exit Function
End If
anyFilename = Trim(anyFilename)
For LC = 1 To Len(anyFilename)
If InStr(InvalidCharacterList, Mid(anyFilename, LC, 1)) Then
ValidateFilename = Mid(anyFilename, LC, 1)
Exit Function
End If
Next

End Function



I pasted yours and made on modification. I changed the Labels to QuoteName
and CustomerName. Other than that it is just as you wrote it.

Thanks in advance
  #12   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 30
Default Saving in Excel

I figured it out. I had a syntax error in my file path.

On a related note. Is there a way that it can save to a folder named as the
CustomerName.

In other words. I have a folder called Quotes. Within this I have sub
-folders named after each customer where there quotes are saved. Ideally I
would like to save each customers quote in the proper folder and in the event
the customer had no folder yet it would simply save to the main quote folder.

Is this possible.

Thanks

Steve

"S Willingham" wrote


This is the code I'm using

Sub SaveWorkbookToFolder()
Dim CustomerName As String
Dim InvoiceNumber As String
Dim SaveToPath As String
Dim userInput As String
Dim anyFilename As String

'Change A1 to the cell your QuoteName is in
'Change B1 to the cell your CustomerName is in
QuoteName = Range("E8").Value
CustomerName = Range("B6").Value

'Change to the folder path need to be sure you have a \ at the end of path
SaveToPath = "\\C:\Documents and Settings\FaroTemplate\Desktop\Quotes\"

anyFilename = QuoteName & _
"_" & CustomerName & ".xls"

If Dir(SaveToPath & anyFilename) = "" Then

ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
Else

Select Case MsgBox _
("A file named: '" & anyFilename & " already exists in " & SaveToPath _
& vbCrLf & "What would you like to do?" & vbCrLf _
& "Overwrite the existing file? [Yes]" & vbCrLf _
& "Save file with a different name? [No]" & vbCrLf _
& "Cancel - do not save this file at this time. [Cancel]", _
vbYesNoCancel + vbExclamation + vbDefaultButton2, "Save Invoice To Folder ")

Case Is = vbYes

Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
Application.DisplayAlerts = True

Case Is = vbNo


userInput = "dummy entry to make it work"

GetFileNameFromUser:
Do While userInput < ""
anyFilename = InputBox$("Enter a new filename to use:", _
"Commission Manager", CustomerName & _
"_" & InvoiceNumber)
If Right(UCase(Trim(anyFilename)), 4) < ".XLS" Then
anyFilename = anyFilename & ".xls"
End If
If ValidateFilename(anyFilename) < "" Then

MsgBox _
"The filename you have entered is not a valid filename." _
& vbCrLf & _
"Filenames may not have any of these characters in them:" _
& vbCrLf & _
" \ / : * ? < | " & Chr$(34) & vbCrLf _
& "Please provide a valid filename.", _
vbOKOnly, "Invalid Filename"
GoTo GetFileNameFromUser
End If
If Trim(UCase(anyFilename)) = ".XLS" Then

If MsgBox("You have chosen to Cancel the file save." & _
"Did you really intend to Cancel this operation?", _
vbYesNo + vbInformation, "Confirm Cancel") < vbYes Then
GoTo GetFileNameFromUser
Else

anyFilename = ":* QUIT *:"
userInput = ""
End If
End If
If userInput < "" Then

userInput = Dir(SaveToPath & anyFilename)
End If
Loop


If anyFilename < ":* QUIT *:" Then

ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
End If

Case Else


Application.DisplayAlerts = False
ActiveWindow.Close
Application.DisplayAlerts = True

End Select
End If

End Sub



Private Function ValidateFilename(anyFilename As String) As String

Dim InvalidCharacterList As String
InvalidCharacterList = "\/:*?<|" & Chr$(34)
Dim LC As Integer

ValidateFilename = ""
If Len(Trim(anyFilename)) = 0 Then
ValidateFilename = "EMPTY"
Exit Function
End If
anyFilename = Trim(anyFilename)
For LC = 1 To Len(anyFilename)
If InStr(InvalidCharacterList, Mid(anyFilename, LC, 1)) Then
ValidateFilename = Mid(anyFilename, LC, 1)
Exit Function
End If
Next

End Function



I pasted yours and made on modification. I changed the Labels to QuoteName
and CustomerName. Other than that it is just as you wrote it.

Thanks in advance

  #13   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,101
Default Saving in Excel

try this
Shouild work as long as the Folder is named the same as Customers Name
SaveToPath = "\\C:\Documents and Settings\FaroTemplate\Desktop\Quotes\" & _
CustomerName & "\"

"S Willingham" wrote:

I figured it out. I had a syntax error in my file path.

On a related note. Is there a way that it can save to a folder named as the
CustomerName.

In other words. I have a folder called Quotes. Within this I have sub
-folders named after each customer where there quotes are saved. Ideally I
would like to save each customers quote in the proper folder and in the event
the customer had no folder yet it would simply save to the main quote folder.

Is this possible.

Thanks

Steve

"S Willingham" wrote


This is the code I'm using

Sub SaveWorkbookToFolder()
Dim CustomerName As String
Dim InvoiceNumber As String
Dim SaveToPath As String
Dim userInput As String
Dim anyFilename As String

'Change A1 to the cell your QuoteName is in
'Change B1 to the cell your CustomerName is in
QuoteName = Range("E8").Value
CustomerName = Range("B6").Value

'Change to the folder path need to be sure you have a \ at the end of path
SaveToPath = "\\C:\Documents and Settings\FaroTemplate\Desktop\Quotes\"

anyFilename = QuoteName & _
"_" & CustomerName & ".xls"

If Dir(SaveToPath & anyFilename) = "" Then

ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
Else

Select Case MsgBox _
("A file named: '" & anyFilename & " already exists in " & SaveToPath _
& vbCrLf & "What would you like to do?" & vbCrLf _
& "Overwrite the existing file? [Yes]" & vbCrLf _
& "Save file with a different name? [No]" & vbCrLf _
& "Cancel - do not save this file at this time. [Cancel]", _
vbYesNoCancel + vbExclamation + vbDefaultButton2, "Save Invoice To Folder ")

Case Is = vbYes

Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
Application.DisplayAlerts = True

Case Is = vbNo


userInput = "dummy entry to make it work"

GetFileNameFromUser:
Do While userInput < ""
anyFilename = InputBox$("Enter a new filename to use:", _
"Commission Manager", CustomerName & _
"_" & InvoiceNumber)
If Right(UCase(Trim(anyFilename)), 4) < ".XLS" Then
anyFilename = anyFilename & ".xls"
End If
If ValidateFilename(anyFilename) < "" Then

MsgBox _
"The filename you have entered is not a valid filename." _
& vbCrLf & _
"Filenames may not have any of these characters in them:" _
& vbCrLf & _
" \ / : * ? < | " & Chr$(34) & vbCrLf _
& "Please provide a valid filename.", _
vbOKOnly, "Invalid Filename"
GoTo GetFileNameFromUser
End If
If Trim(UCase(anyFilename)) = ".XLS" Then

If MsgBox("You have chosen to Cancel the file save." & _
"Did you really intend to Cancel this operation?", _
vbYesNo + vbInformation, "Confirm Cancel") < vbYes Then
GoTo GetFileNameFromUser
Else

anyFilename = ":* QUIT *:"
userInput = ""
End If
End If
If userInput < "" Then

userInput = Dir(SaveToPath & anyFilename)
End If
Loop


If anyFilename < ":* QUIT *:" Then

ActiveWorkbook.SaveAs Filename:=SaveToPath & anyFilename
End If

Case Else


Application.DisplayAlerts = False
ActiveWindow.Close
Application.DisplayAlerts = True

End Select
End If

End Sub



Private Function ValidateFilename(anyFilename As String) As String

Dim InvalidCharacterList As String
InvalidCharacterList = "\/:*?<|" & Chr$(34)
Dim LC As Integer

ValidateFilename = ""
If Len(Trim(anyFilename)) = 0 Then
ValidateFilename = "EMPTY"
Exit Function
End If
anyFilename = Trim(anyFilename)
For LC = 1 To Len(anyFilename)
If InStr(InvalidCharacterList, Mid(anyFilename, LC, 1)) Then
ValidateFilename = Mid(anyFilename, LC, 1)
Exit Function
End If
Next

End Function



I pasted yours and made on modification. I changed the Labels to QuoteName
and CustomerName. Other than that it is just as you wrote it.

Thanks in advance

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
Excel not saving changes [email protected] Excel Discussion (Misc queries) 2 January 18th 07 02:14 PM
Excel saving bushno8 Excel Discussion (Misc queries) 1 November 6th 06 05:09 PM
Saving Excel as a CSV Nitu Excel Discussion (Misc queries) 2 June 15th 06 09:52 PM
excel saving as a xls? Mrs. Joey Excel Discussion (Misc queries) 2 February 16th 06 09:41 PM
excel saving puzzled Excel Discussion (Misc queries) 0 March 3rd 05 01:35 AM


All times are GMT +1. The time now is 12:51 PM.

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

About Us

"It's about Microsoft Excel"