+ Reply to Thread
Results 1 to 3 of 3

.Save, .Activate, .Close not working in Macro

Hybrid View

  1. #1
    Registered User
    Join Date
    08-25-2011
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2003
    Posts
    13

    .Save, .Activate, .Close not working in Macro

    This is a weird problem, I'm hoping you guys can help. I've written a pretty basic macro to pull information from one workbook to the other. This part works perfectly fine, but any .Activate, or .Close function does not work. Application.Quit does not work as well (although that is not what I want it to do). I at first thought it was a problem with our remote management software, but a simple macro of "ActiveWorkbook.Close False" does in fact work all alone.

    Here is the code:

    Sub update()
    '
    ' update Macro
    ' Macro recorded 8/25/2011 by jstephens
    '
    Dim cashsheet As Workbook
    Dim cashsum As Workbook
    Dim rangefinder As Range
    Dim date1 As String
    Dim row As Integer
    Dim prop As String
    Dim loopnum As Integer
    loopnum = 3
    
    Application.ScreenUpdating = False
    Set cashsum = ThisWorkbook
    
    Workbooks.Open ("G:\CASH SHEETS\CASH SHEETS 2011\Texas\0911_Texas.xls")
    Set cashsheet = ActiveWorkbook
    
    
    date1 = cashsheet.Sheets(1).Range("A6").Value
    cashsum.Sheets(1).Range("A2") = date1
    
    Do
    
    prop = cashsum.Sheets(1).Range("B" & loopnum).Value
    If prop = "" Then
    Exit Sub
    End If
    cashsheet.Sheets(prop).Activate
    Set rangefinder = Columns(4).Find(What:="stophere", After:=Cells(3, 4), LookIn:=xlFormulas, LookAt _
            :=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False)
    row = rangefinder.row
    row = row - 1
    cashsum.Sheets(1).Range("C" & loopnum) = cashsheet.Sheets(prop).Range("G12").Value
    cashsum.Sheets(1).Range("D" & loopnum) = cashsheet.Sheets(prop).Range("D" & row).Value * -1
    cashsum.Sheets(1).Range("E" & loopnum) = cashsheet.Sheets(prop).Range("E" & row).Value
    cashsum.Sheets(1).Range("F" & loopnum) = cashsheet.Sheets(prop).Range("F" & row).Value
    cashsum.Sheets(1).Range("G" & loopnum) = cashsheet.Sheets(prop).Range("G" & row).Value
    loopnum = loopnum + 1
    Loop
    Application.ScreenUpdating = True
    
    Application.Quit
    
    
    End Sub
    Any suggestion on code optimization is appreciated, but I really need the opened workbook to close.
    Last edited by jstephens; 08-26-2011 at 09:49 AM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: .Save, .Activate, .Close not working in Macro

    Hello jstephens,

    Welcome to the Forum!

    With the exception of Application.Quit I don't see .Save, .Activate, or .Close in the code you provided. On potential problem I do see is that you exit the Sub with restoring screen updating.
    If prop = "" Then
    Exit Sub
    End If

    Write a Sub to re-enable screen updating, and change your macro to re-enable screen updating before exiting. Rerun the macro and see if the changes help your problem.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    08-25-2011
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: .Save, .Activate, .Close not working in Macro

    Quote Originally Posted by Leith Ross View Post
    Hello jstephens,

    Welcome to the Forum!

    With the exception of Application.Quit I don't see .Save, .Activate, or .Close in the code you provided. On potential problem I do see is that you exit the Sub with restoring screen updating.
    If prop = "" Then
    Exit Sub
    End If

    Write a Sub to re-enable screen updating, and change your macro to re-enable screen updating before exiting. Rerun the macro and see if the changes help your problem.
    That's embarassing, I had just changed something because of that and didn't put two and two together. Thanks a lot!

+ 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