+ Reply to Thread
Results 1 to 3 of 3

Run-time error '1004': Method 'Sheets' of object '_Global' failed

Hybrid View

  1. #1
    Registered User
    Join Date
    11-17-2013
    Location
    Norway
    MS-Off Ver
    Excel 2003 and 2013
    Posts
    2

    Run-time error '1004': Method 'Sheets' of object '_Global' failed

    I am using a vba code in Excel for storing a workbook every two minutes. This is running Global, used via network in an Access database. The workbook is showing data from a Counter measures liters on ten different lines.

    This VBA code also takes a backup of the spread sheets data at seven o'clock every morning to a sheet in the workbook called History.

    When starting the Workbook (Tmb.xls) I am getting the fault "Run-time error '1004': Method 'Sheets' of object '_Global' failed"

    In Debug it is stopping in the line: Sheets("Beer Count").Select, its marked in the code.

    This means I have to start the macro manually, and then every thing is working OK.

    It needs the macro to run automatically on start-up.

    Can anybody help? Please?




    Option Explicit
    'So If I want the macro to run at 07:00:00 and stop at 07:01:50
    'and have it run once between those times, as daily backup on an
    'other under sheet History.
    'I also want to save the open workbook every two minutes.
    
    Public RunWhen As Double
    Public Const cRunIntervalSeconds As Long = 120 '60 seconds * 10 minutes
    Public Const cRunWhat As String = "SpreadRecordMacro1"
    Public Const cRunMinute As String = "Auto_Minute"
    Public Const BeginTime As Date = ("07:00:00")
    Public Const FinishTime As Date = ("07:01:50")
    Public Const StartTime As Date = ("00:00:00")
    
    
    Sub Auto_Open()
    If Time < BeginTime Then
    'wait until that time
    Application.OnTime earliesttime:=BeginTime, _
    procedure:=cRunWhat
    Else
    'just start it right now????
    Application.Run cRunWhat
    End If
    End Sub
    
    
    Sub Auto_Close()
    'if you're closing the workbook, then
    'stop the timer from reopening your workbook
    'and running the macro!!
    Call StopTimer
    End Sub
    
    
    Sub StartTimer()
    RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
    Application.OnTime earliesttime:=RunWhen, procedure:=cRunWhat, _
    Schedule:=True
    End Sub
    
    
    Sub SpreadRecordMacro1()
    
    Sheets("Beer count").Select
        Range("A4:D20").Select
        Selection.Copy
        Sheets("History").Select
        [a1].Select
        ActiveCell.Offset(3, ActiveCell).Select
        Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, _
            SkipBlanks:=False, Transpose:=False
        [a1].Select
        ActiveCell.Value = ActiveCell.Value + 5
        Sheets("Beer count").Select
        [a1].Select
        ActiveWorkbook.Save
        ThisWorkbook.Saved = True
    
    '600/60/24 is 10 minutes
    'so check to see if it's too late to schedule the next
    'run
    If Time > (FinishTime - (cRunIntervalSeconds / 12 / 24)) Then
    'don't start it again.
    Else
    StartTimer
    End If
    End Sub
    
    
    Sub StopTimer()
    On Error Resume Next
    Application.OnTime earliesttime:=RunWhen, procedure:=cRunWhat, _
    Schedule:=False
    End Sub
    
    
    Sub Workbook_Open()
    If Time <> StartTime Then
    Application.Run cRunMinute
    
    End If
    End Sub
    
    Sub Auto_Minute()
    Application.OnTime Now + TimeValue("00:02:00"), "Workbook_Open"
    'fungerer bare hvis arket er delt
    Workbooks("Tmb.xls").AcceptAllChanges Who:="Everyone"
    Application.DisplayAlerts = False
    Workbooks("Tmb.xls").Save
    Application.DisplayAlerts = True
    
    End Sub

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Run-time error '1004': Method 'Sheets' of object '_Global' failed

    Well two possibilities I can think of:
    -There is no sheet called "Beer count" in the active workbook
    -The sheet "Beer count" is hidden

  3. #3
    Registered User
    Join Date
    11-17-2013
    Location
    Norway
    MS-Off Ver
    Excel 2003 and 2013
    Posts
    2

    Re: Run-time error '1004': Method 'Sheets' of object '_Global' failed

    Thank you very much.

    Suppose I have to live with it. I can't find any fault.

    It is important to get it start Automatic. We are depending on it to pay tax to the authorities.

    It is dangerous for us, if macros don’t start when we open the workbook.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Run-time error 1004 - Method 'Range' of object'_Global' failed
    By onmyway in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-24-2013, 03:33 PM
  2. [SOLVED] Run time error 1004: method range of object _global failed
    By Danry in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-07-2012, 07:31 PM
  3. Run-time-error 1004 -- Method 'Range' of object '_Global' failed
    By tilleyd in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-04-2012, 10:55 PM
  4. Run-time error '1004': Method 'Range' of object '_Global' failed
    By claremount in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 03-26-2010, 08:01 AM
  5. [SOLVED] Run-time error '1004': Method 'Cells' of object _Global failed
    By Fran D in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-12-2006, 11:50 AM

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