Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Save as filename

I have a workbook that is read only so can't be saved. When the users does
'save as' how can I add a letter to the beginning of whatever filename he
chooses. It will be the same letter each time.

M
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Save as filename

You can give this a try...

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim strFileName As String
Dim lngLastSlash As Long
If SaveAsUI = True Then
Cancel = True
strFileName = Application.GetSaveAsFilename
lngLastSlash = InStrRev(strFileName, "\")
strFileName = Left(strFileName, lngLastSlash) & "Z" &
Mid(strFileName, lngLastSlash + 1, 256)
ThisWorkbook.SaveAs strFileName
End If
End Sub
--
HTH...

Jim Thomlinson


"Mike H" wrote:

I have a workbook that is read only so can't be saved. When the users does
'save as' how can I add a letter to the beginning of whatever filename he
chooses. It will be the same letter each time.

M

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Save as filename

Jim,

Perfect, thank you.

Mike

"Jim Thomlinson" wrote:

You can give this a try...

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim strFileName As String
Dim lngLastSlash As Long
If SaveAsUI = True Then
Cancel = True
strFileName = Application.GetSaveAsFilename
lngLastSlash = InStrRev(strFileName, "\")
strFileName = Left(strFileName, lngLastSlash) & "Z" &
Mid(strFileName, lngLastSlash + 1, 256)
ThisWorkbook.SaveAs strFileName
End If
End Sub
--
HTH...

Jim Thomlinson


"Mike H" wrote:

I have a workbook that is read only so can't be saved. When the users does
'save as' how can I add a letter to the beginning of whatever filename he
chooses. It will be the same letter each time.

M

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Save as filename

Mike,

Try something like this in the Thisworkbook code module:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim strFile As String
Dim iReply As Integer

Cancel = True
iReply = vbYes

'Check if read only
If ThisWorkbook.ReadOnly Then
Do
strFile = Application.GetSaveAsFilename
If strFile = "False" Then Exit Sub 'user cancelled

'Add "X" to the file name
strFile = Mid(strFile, 1, InStrRev(strFile, "\")) & "X" &
Mid(strFile, InStrRev(strFile, "\") + 1)

'Check if file exists
If Dir(strFile) < "" Then
iReply = MsgBox(strFile & " already exists! Overwrite?",
vbYesNo)
End If
Loop While iReply = vbNo

'Save it
Application.EnableEvents = False
Application.DisplayAlerts = False
ThisWorkbook.SaveAs strFile
Application.DisplayAlerts = True
Application.EnableEvents = True

End If
End Sub



--
Hope that helps.

Vergel Adriano


"Mike H" wrote:

I have a workbook that is read only so can't be saved. When the users does
'save as' how can I add a letter to the beginning of whatever filename he
chooses. It will be the same letter each time.

M

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Save as filename

... correction.. Cancel=True line should be inside the If statement..

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim strFile As String
Dim iReply As Integer

iReply = vbYes

'Check if read only
If ThisWorkbook.ReadOnly Then
Cancel = True

Do
strFile = Application.GetSaveAsFilename
If strFile = "False" Then Exit Sub 'user cancelled

'Add "X" to the file name
strFile = Mid(strFile, 1, InStrRev(strFile, "\")) & "X" &
Mid(strFile, InStrRev(strFile, "\") + 1)

'Check if file exists
If Dir(strFile) < "" Then
iReply = MsgBox(strFile & " already exists! Overwrite?",
vbYesNo)
End If
Loop While iReply = vbNo

'Save it
Application.EnableEvents = False
Application.DisplayAlerts = False
ThisWorkbook.SaveAs strFile
Application.DisplayAlerts = True
Application.EnableEvents = True

End If
End Sub



--
Hope that helps.

Vergel Adriano


"Vergel Adriano" wrote:

Mike,

Try something like this in the Thisworkbook code module:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim strFile As String
Dim iReply As Integer

Cancel = True
iReply = vbYes

'Check if read only
If ThisWorkbook.ReadOnly Then
Do
strFile = Application.GetSaveAsFilename
If strFile = "False" Then Exit Sub 'user cancelled

'Add "X" to the file name
strFile = Mid(strFile, 1, InStrRev(strFile, "\")) & "X" &
Mid(strFile, InStrRev(strFile, "\") + 1)

'Check if file exists
If Dir(strFile) < "" Then
iReply = MsgBox(strFile & " already exists! Overwrite?",
vbYesNo)
End If
Loop While iReply = vbNo

'Save it
Application.EnableEvents = False
Application.DisplayAlerts = False
ThisWorkbook.SaveAs strFile
Application.DisplayAlerts = True
Application.EnableEvents = True

End If
End Sub



--
Hope that helps.

Vergel Adriano


"Mike H" wrote:

I have a workbook that is read only so can't be saved. When the users does
'save as' how can I add a letter to the beginning of whatever filename he
chooses. It will be the same letter each time.

M



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
Cell("filename") doesn't update to new filename when do save as. Louis Excel Worksheet Functions 2 March 22nd 07 07:27 PM
VBA - Save with New Filename Louise Excel Programming 2 October 13th 06 01:59 PM
VBA - Save with new filename Louise Excel Programming 1 October 13th 06 01:50 PM
save as different filename Tom Excel Programming 3 May 4th 05 03:41 AM
Save Filename Peter Excel Programming 3 February 4th 05 01:15 PM


All times are GMT +1. The time now is 02:15 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"