LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default ActiveWorkbook.SaveAs does not work

Hi everyone,

I've created these two subs in an Excel template, which, in my humble
opinion, should prompt the user with a filename each time a worksheet based
on the template is saved. The template contains the Name "klant" which refers
to a single cell that currently contains the text "qqq". The code below is
stored in the ThisWorkbook section.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Not ActiveWorkbook.Saved Then
ActiveWorkbook.Save
End If
If Not ActiveWorkbook.Saved Then ' Cancel is chosen in the SaveAs dialog
Cancel = True
End If
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
' This sub proposes a name each time a save occurs (ddMMyy hhnn <klant.xls).
Dim strFileName As String, varResult As Variant

If Right(LCase(ActiveWorkbook.Name), 3) < "xlt" Then ' leave .xlt alone
Cancel = True ' do not save by default
strFileName = Format(Date, "ddMMyy ") & Format(Time, "hhnn ") & _
Application.Range("klant").Value & ".xls"

varResult =
Application.GetSaveAsFilename(InitialFileName:=str FileName)
If varResult < False Then
Application.EnableEvents = False ' or else another
Workbook_BeforeSave
ActiveWorkbook.SaveAs Filename:=CStr(varResult) ' DOES NOT WORK
Application.EnableEvents = True
End If
End If

End Sub

In stepping through the code I find that the line with
ActiveWorkbook.SaveAs... gets reached when it should and that a valid
filename is provided - however, nothing is saved. Can anyone confirm this
mystery and if yes - is there a remedy?

Thank you,
Cooz
 
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
Help with ActiveWorkbook.SaveAs Martin X. Excel Programming 3 August 15th 07 02:15 PM
ActiveWorkbook.SaveAs franks Excel Programming 6 August 6th 07 10:04 PM
ActiveWorkbook.SaveAs problem SandyUK[_11_] Excel Programming 2 November 14th 05 02:54 PM
ActiveWorkbook.SaveAs Problem SowBelly Excel Programming 4 August 4th 04 10:58 PM
activeworkbook.saveas J Silver Excel Programming 0 June 25th 04 09:01 PM


All times are GMT +1. The time now is 05:43 AM.

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"