+ Reply to Thread
Results 1 to 5 of 5

Object variable or with block variable not set

Hybrid View

techexpressinc2 Object variable or with block... 02-07-2011, 12:49 PM
romperstomper Re: Object variable or with... 02-07-2011, 12:53 PM
techexpressinc2 listobject - how to 02-07-2011, 04:41 PM
royUK Re: Object variable or with... 02-08-2011, 04:04 AM
techexpressinc2 Solved! - the open close... 02-18-2011, 02:17 PM
  1. #1
    Registered User
    Join Date
    01-21-2011
    Location
    usa
    MS-Off Ver
    Excel 2007
    Posts
    17

    Object variable or with block variable not set

    I need to refresh my Excel-workbook with 2 worksheets from Access and save it a to a different file name to be picked up by an Outlook Email Task schedule.

    Part 1 getting the Excel updated:
    My plan is to having XP Scheduled Task to open the Workbook with a Macro named Auto_Open to do the refreshes and that Marco to save the Workbook as a non-Macro spreadsheet.
    Part 2:
    Then have an Outlook task to email the non-Macro Excel workbook out. Then another XP Scheduled Task scheduled task to delete the non-Macro Excel workbook for the next night the process goes again.

    Part 1 is having problems:

    The refresh all on open was working but I needed to get the Excel saved without the Refresh on open process. So, I added a Save As non-marco notebook into the Marco.

    Then Excel was giving me the message on the save as part of the macro:
    "This action will cancel a pending Refresh Data command.".

    So, broke apart the refreshes to refresh one workbook then the next; I am now getting the message:
    "Object variable or with block variable not set"

    
    Sub Auto_Open()
    '
    ' Auto_Open Macro
    '
    
    '
        Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
        Sheets("2010 Tracking Database 5500").Select
        Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
        Sheets("Key").Select
        ActiveWorkbook.SaveAs Filename:= _
            "C:\Documents and Settings\neumar1\My Documents\PART1refreshMarco.xlsm", _
            FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
    End Sub

    Any help on a process improvement or fix to the current approach will be appreciated.

    Thx
    Russ

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,008

    Re: Object variable or with block variable not set

    Your code assumes that the currently selected cell is in a table - not a good idea. You would be better off specifying the listobject you want to refresh, either by name or index number.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    01-21-2011
    Location
    usa
    MS-Off Ver
    Excel 2007
    Posts
    17

    listobject - how to

    Could you give me an example out to turn the worksheet into a listobject?
    Thx

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Object variable or with block variable not set

    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Registered User
    Join Date
    01-21-2011
    Location
    usa
    MS-Off Ver
    Excel 2007
    Posts
    17

    Solved! - the open close create a wrkbk to be emailed

    
    Sub Auto_Open()
    '
    ' Auto_Open Macro
    ' Refresh Query
    '
    
    If Sheets("Key").Range("A1") <> "" Then Exit Sub
    
    '
    Worksheets("Key").Range("A1").Value = Date
    
    '
    
        ActiveWorkbook.RefreshAll
        
    
    '
    ChDir _
            "C:\Documents and Settings\neumar1\My Documents\@DARIN ASSIGNMENT1\FEB15840am"
        ActiveWorkbook.SaveAs Filename:= _
            "C:\Documents and Settings\neumar1\My Documents\@DARIN ASSIGNMENT1\FEB15845am\AccountManagementStatusPlan930amToBeEmailed.xls" _
            , FileFormat:=xlExcel8, Password:="", WriteResPassword:="", _
            ReadOnlyRecommended:=False, CreateBackup:=False
     
      Application.Quit
        
    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