Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 2nd, 2007, 09:02 AM
Registered User
 
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default msoFileDialogSaveAs failure

I have a workbook that is open to several users. Data entry is password controlled and each user has different permissions. I have a password system that unlocks various (differing) areas of the spreadsheet for each user.

I use Workbook_BeforeSave to intercept and cancel the excel save, replacing it with my own save routine which locks the user areas before the save, then saves the file, then restores the workbook to its previous condition so the user can continue working.

I use an IF statement to test whether the user used FileSave or FileSaveAs and THEN present the file dialogue box for FileSaveAs if required.

I thought my code was pretty neat and it works perfectly on my computer BUT () in testing on another computer the FileSaveAs branch shows the dialog box but then fails to save. Instead, I get a run time error:

-2147467259 (80004005)
Method Execute of FileDialog failed


Same version of excel on both machines - 2003 SP2

The code is:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

...various lines that lock the cells...

If SaveAsUI = True Then
    With Application.FileDialog(msoFileDialogSaveAs)
        If .Show Then .Execute
    End With
Else
    ThisWorkbook.Save
End If
Cancel = True

...various lines that identify the user and unlock the relevant
cells for data entry...

I assume I could get the path and filename from the dialog box and then wite code to use .SaveAs but using .Execute on the dialog box looked like a more elegant solution.

Any ideas?

Alistair
 
Old January 3rd, 2007, 10:05 AM
Registered User
 
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Stranger and stranger.
Same PC, same file- now the unmodified code works.
So it's a daisy - some days it works and some days it doesn't.

Any ideas?

 
Old January 5th, 2007, 08:33 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 173
Thanks: 0
Thanked 3 Times in 3 Posts
Default

I've heard of issues with Application.FileDialog(msoFileDialogSaveAs)
 before. Have you tried using Application.GetSaveAsFileName instead? This will involve you extracting the requested file save name and then saving this new filename and therefore less elegant but more robust.

Maccas

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

' ...various lines that lock the cells...

If SaveAsUI = True Then
    Dim Retval As Variant 
    With Application 
        Retval = .GetSaveAsFilename("C:\Temp\Test.xls") 
        If Retval = False Then Goto Ender
        ThisWorkbook.SaveAs Retval 
    End With
Else
    ThisWorkbook.Save
End If

Ender:
Cancel = True
' ...various lines that identify the user and unlock the relevant 
' cells for data entry...





Similar Threads
Thread Thread Starter Forum Replies Last Post
login failure yasminnnnn BOOK: ASP.NET Website Programming Problem-Design-Solution 2 February 27th, 2007 04:16 AM
Before Close Failure RollingWoodFarm Excel VBA 1 January 3rd, 2007 03:09 PM
Another Login failure Bo.B.B BOOK: Beginning VB.NET Databases 6 July 10th, 2005 04:02 AM
Cryptographic failure u-reddy BOOK: ASP.NET Website Programming Problem-Design-Solution 7 November 16th, 2004 09:48 AM
QueryInterface failure druid2112 General .NET 0 June 28th, 2004 10:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.