+ Reply to Thread
Results 1 to 11 of 11

Object Required error

  1. #1
    Forum Contributor
    Join Date
    01-12-2004
    Location
    Nebraska, USA
    MS-Off Ver
    Office 365
    Posts
    167

    Object Required error

    Why doesn't this code work??

    I keep getting an "Object Required" error.

    Please Login or Register  to view this content.
    The error is reported on the Set NewFileName line.

    Also, how do I write the code to save the file to the an end user's Desktop?
    Last edited by HuskerBronco; 12-20-2011 at 02:57 PM.

  2. #2
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Object Required error

    You don't need to set a Long Variable from what I can tell. And your code is missing some things.
    Try this

    Please Login or Register  to view this content.
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  3. #3
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Object Required error

    A Long isn't an object so you can't set it.

    Try this

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    01-12-2004
    Location
    Nebraska, USA
    MS-Off Ver
    Office 365
    Posts
    167

    Re: Object Required error

    Thanks, guys...for the help.

    I got the macro to create & name the files as requested...and place them on MY desktop during testing.

    JapanDave said:
    You don't need to set a Long Variable from what I can tell.
    Yeah...sorry about that. I originally had it set as STRING. In an effort to get the macro to work...I was trying everything...including changing the variable type.

    Kyle123 said:
    A Long isn't an object so you can't set it.
    And there lies my main error. I'm still fairly new at this VBA and didn't realize I was trying to SET a variable.

    Also, Kyle123:

    Your code to set the new workbooks to the END USER'S desktop returns a syntax error at the following line:
    ActiveWorkbook.saveas Filename:=DesktopPathDir & NewFileName,
    FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
    Do I need to change something, here? ...or in the function ??

  5. #5
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Object Required error

    Dunno I've only got 2003, what's in the range that you are setting as the workbook name. Do you need to include the extension?

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Object Required error

    you don't need any declaration:
    Please Login or Register  to view this content.
    Last edited by snb; 12-20-2011 at 10:44 AM.



  7. #7
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Object Required error

    Your original code is bad.

    I posted the code for this earlier. Copy this and see how you go?

    Please Login or Register  to view this content.
    Edit: Or just follow Snb's code.

  8. #8
    Forum Contributor
    Join Date
    01-12-2004
    Location
    Nebraska, USA
    MS-Off Ver
    Office 365
    Posts
    167

    Re: Object Required error

    Yep...the range is a concatenation of cell value PLUS ".xlsm"
    Last edited by HuskerBronco; 12-20-2011 at 09:31 PM. Reason: correct typo

  9. #9
    Forum Contributor
    Join Date
    01-12-2004
    Location
    Nebraska, USA
    MS-Off Ver
    Office 365
    Posts
    167

    Re: Object Required error

    Yep....I left out the code continuation underscore.

  10. #10
    Forum Contributor
    Join Date
    01-12-2004
    Location
    Nebraska, USA
    MS-Off Ver
    Office 365
    Posts
    167

    Re: Object Required error

    snb...

    I had no idea you could code this without declarations.

    My question is...what is the 52 in the following line ?? :
    Please Login or Register  to view this content.
    Wait...that's the code number for the file format...isn't it ??

  11. #11
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Object Required error

    Bingo ! You hit it.

+ 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