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


Reply
 
Thread Tools Display Modes
  #1  
Old 09-24-2004, 02:38 AM
littledizzy littledizzy is offline
Freshman
 
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....
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 04:22 AM. Reason: [vb] tags
Reply With Quote
  #2  
Old 09-24-2004, 04:26 AM
herilane's Avatar
herilane herilane is offline
Unashamed geek

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

You can check whether or not the user cancelled by checking strFName:
Code:
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
Reply


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

Advertisement:





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.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
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..
subscribe
 
 
-->