+ Reply to Thread
Results 1 to 2 of 2

error on ActiveWorkbook.Close

  1. #1
    lesviago
    Guest

    error on ActiveWorkbook.Close

    I am having trouble with the following macro. It works fine one or two
    times, but if I use it three times, I get a dialog box that says "Program
    Error" with nothing else but an o.k. button. If I select o.k. or leave it
    alone for a few seconds, all Excel windows close. The error occurs at the
    ActiveWorkbook.Close line four lines up from the bottom.

    Can anybody help?

    Sub CREATEPSR()
    '
    ' CREATEPSR Macro
    ' Macro recorded 1/27/2005 by me
    '

    '
    On Error Resume Next
    Sheets("PSR").Copy
    ChDir "C:\Documents and Settings\" & Application.UserName & "\Desktop"

    Range("C69:C71").Select
    Application.CutCopyMode = False
    Selection.Copy
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=False

    Range("A1").Select
    Application.CutCopyMode = False
    Selection.Copy
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=False

    Application.DisplayAlerts = False
    ActiveWorkbook.SaveAs Filename:="C:\Documents and Settings\" &
    Application.UserName & "\Desktop\" & Cells(1, 1) & Format(Date, "
    yyyy-mm-dd"), FileFormat:=xlNormal, _
    Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
    CreateBackup:=False
    Application.DisplayAlerts = True

    ActiveWorkbook.Save
    ActiveWorkbook.Close
    Sheets("Main").Select
    Range("D6").Select
    End Sub


  2. #2
    K Dales
    Guest

    RE: error on ActiveWorkbook.Close

    You are trying to select the sheet "Main" and range "D6" AFTER the
    ActiveWorkbook saves and closes - why? Are you initiating this code from a
    different workbook? If not, you are trying to run code that exists as part
    of the workbook after the book closes - if so, the code probably comes
    crashing down and the error message is non-specific due to the volatile
    nature of the code and then disappears as the session fades off into
    cyberspace...


    "lesviago" wrote:

    > I am having trouble with the following macro. It works fine one or two
    > times, but if I use it three times, I get a dialog box that says "Program
    > Error" with nothing else but an o.k. button. If I select o.k. or leave it
    > alone for a few seconds, all Excel windows close. The error occurs at the
    > ActiveWorkbook.Close line four lines up from the bottom.
    >
    > Can anybody help?
    >
    > Sub CREATEPSR()
    > '
    > ' CREATEPSR Macro
    > ' Macro recorded 1/27/2005 by me
    > '
    >
    > '
    > On Error Resume Next
    > Sheets("PSR").Copy
    > ChDir "C:\Documents and Settings\" & Application.UserName & "\Desktop"
    >
    > Range("C69:C71").Select
    > Application.CutCopyMode = False
    > Selection.Copy
    > Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
    > False, Transpose:=False
    >
    > Range("A1").Select
    > Application.CutCopyMode = False
    > Selection.Copy
    > Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
    > False, Transpose:=False
    >
    > Application.DisplayAlerts = False
    > ActiveWorkbook.SaveAs Filename:="C:\Documents and Settings\" &
    > Application.UserName & "\Desktop\" & Cells(1, 1) & Format(Date, "
    > yyyy-mm-dd"), FileFormat:=xlNormal, _
    > Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
    > CreateBackup:=False
    > Application.DisplayAlerts = True
    >
    > ActiveWorkbook.Save
    > ActiveWorkbook.Close
    > Sheets("Main").Select
    > Range("D6").Select
    > End Sub
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1