Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Excel > could use some help or feedback on my saveas function

Thread Tools Display Modes
Old 09-24-2004, 01:38 AM
littledizzy littledizzy is offline
Join Date: Jul 2004
Posts: 26
Question could use some help or feedback on my saveas function

Now on my machine which has OS-XP, Excel-2000 my code works fine when I save, but it's not working for Excel-XP, meaning it just crashes and closes Excel altogether.

As I said my code works fine when I save, but if I hit Cancel, a False.xls seems to want to be saved and if I hit No or Cancel on that prompt, it has me debug my code.

I'm obviously not an expert, am actually learning more as I go, so any help would be greatly appreciated.

So this is my code....
Sub SaveWorkbook() Dim Newname As String Newname = Range("A1").Value Dim strFName As Variant Dim aExcel As Excel.Application Set aExcel = CreateObject("Excel.Application") Dim wExcel As Excel.Workbook Set wExcel = ActiveWorkbook strFName = aExcel.GetSaveAsFilename(Newname, FileFilter:="Excel Files (*.xls), *.xls") wExcel.SaveAs FileName:=strFName, FileFormat _ :=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:= _ False, CreateBackup:=False Set wExcel = Nothing Set aExcel = Nothing End Sub

Last edited by herilane; 09-24-2004 at 03:22 AM. Reason: [vb] tags
Reply With Quote
Old 09-24-2004, 03:26 AM
herilane's Avatar
herilane herilane is offline
Unashamed geek

Retired Moderator
* Expert *
Join Date: Jul 2003
Location: London, England
Posts: 8,988

You can check whether or not the user cancelled by checking strFName:
If strFName = CStr(False) Then 'do not save Else 'continue with your code End If
It's safer to compare to CStr(False) than to "False", in case your users have a non-English version of Excel.
Reply With Quote

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..