Errorhandler VBA - help please

dwilson38550m

Board Regular
Joined
Nov 21, 2005
Messages
89
Hi,

I wonder if someone can help me with an error handler. I need to have an error handler which when the operation fails, points to cell O1 of tab called "Data Sheet" and saves the file to the location on cell O1 (eg C:\Testfile\Example.xls). Here is what I have so far - can anyone suggest anything? Thanks in advance.

VBA Code:
    Sheets("Data Sheet").Select
    Range("O1").Select
    future5 = ActiveCell
continue:      ActiveWindow.ActivateNext
    Application.DisplayAlerts = False
    Rem ActiveWorkbook.Close SaveChanges:=FALSE
   
    ActiveWorkbook.SaveAs Filename:=future5, _
        FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
        ReadOnlyRecommended:=False, CreateBackup:=False
   
       
    Application.DisplayAlerts = True

    ActiveWorkbook.Close SaveChanges:=False
    Sheets("data sheet").Select
    Range("A1").Select
   
   
Errorhandler:
    If Err.Number = 91 Then
    Err.Clear
    GoTo continue
    End If
    If Err.Number = 1004 Then
   
    End If
'
    Range("A6").Select
End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Try something like this instead to trap errors in saving the workbook

VBA Code:
On Error Resume Next
ActiveWorkbook.SaveAs Filename:=future5
Select case Err.number 'trap certain error numbers
case 91
  ActiveWorkbook.SaveAs Filename:=sheets( "Data Sheet" ").range("O1")
  Exit Sub ' or whatever you want to do when there is an error
case 1004
  'do whatever you want here
End Select
On Error Goto 0
'carry on if no error
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,276
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top