Consulting

Results 1 to 3 of 3

Thread: Solved: compile error with simple macro

  1. #1

    Solved: compile error with simple macro

    Hi there
    I'm trying to create a simple macro that will check in a hidden sheet if the current date (cell J6) is greater than the set Expiration date (cell K6). (See code below). If this condition is met, I want the workbook to close otherwise to proceed, with the other commands, which are to hide all the hidden sheets and activate the first sheet. The latter commands work fine, but the initial bit of checking the dates and closing the workbook, returns a Compile Error...

    What am I doing wrong????

    Thanks
    Sunil
    p.s I am new to VBA, so I'm probably doing something very obviously wrong here.....

    [vba]Private Sub Workbook_Open()
    'Turn off screen updates
    Application.ScreenUpdating = False

    With ActiveWorkbook.Worksheets("H00-Reference Data")
    If Range("J6").Value > Range("K6").Value Then
    ActiveWorkbook.Close False
    End If
    End With

    Else
    'Hide confidential sheet at startup
    Call HideSheets

    With Worksheets("Project-Nav")
    .Activate
    .Range("D5").Select
    End With

    'Restore screen updates
    Application.ScreenUpdating = True
    End Sub[/vba]

  2. #2
    Try out with this...


    Private
    Sub Workbook_Open()
    'Turn off screen updates
    Application.ScreenUpdating = False

    With ActiveWorkbook.Worksheets("H00-Reference Data")
    If Range("J6").Value > Range("K6").Value Then
    ActiveWorkbook.Close False
    Else

    'Hide confidential sheet at startup
    Call HideSheets

    With Worksheets("Project-Nav")
    .Activate
    .Range("D5").Select
    End With
    End If
    End With

    'Restore screen updates
    Application.ScreenUpdating = True
    End Sub
    Regards
    Senthil

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You should also dot qualify theranges

    [vba]

    Private Sub Workbook_Open()
    'Turn off screen updates
    Application.ScreenUpdating = False

    With ActiveWorkbook.Worksheets("H00-Reference Data")
    If .Range("J6").Value > .Range("K6").Value Then
    ActiveWorkbook.Close False
    End If
    End With

    'Hide confidential sheet at startup
    Call HideSheets

    With Worksheets("Project-Nav")
    .Activate
    .Range("D5").Select
    End With

    'Restore screen updates
    Application.ScreenUpdating = True
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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