Results 1 to 3 of 3

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

Threaded 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.

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