+ Reply to Thread
Results 1 to 12 of 12

sheet not saving in correct filepath, instead its saving it to My Documents

  1. #1
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    sheet not saving in correct filepath, instead its saving it to My Documents

    I have the following code, working except that its not saving the new spreadsheet in the correct folder. (instead it is saving it to My Documents folder). I need it to save in the parent folder of the initial spreadsheet.
    I added a line (now commented out) that does save the file in the correct path, but then the macro does a dump and fails further down the line.
    Please Login or Register  to view this content.
    when i uncomment out this line, the macro fails

    Please Login or Register  to view this content.
    can anyone help me with this?

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: sheet not saving in correct filepath, instead its saving it to My Documents

    I don't see anything wrong with that. I seldom rely on relative file references. I use full drive:\path\filename.ext paths.

  3. #3
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: sheet not saving in correct filepath, instead its saving it to My Documents

    when i put the full path in, the macro fails here:

    Please Login or Register  to view this content.
    thoughts?

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: sheet not saving in correct filepath, instead its saving it to My Documents

    If you don't specify the path to save file it will be saved in what Excel/VBA sees as the current directory, which may or may not be what you want/think it is.

    How does the code fail when you use this?
    Please Login or Register  to view this content.
    Also, why are you saving the newly added workbook here,
    Please Login or Register  to view this content.
    then, even though you haven't closed it, re-opening it here,
    Please Login or Register  to view this content.
    and then again re-opening it.
    Please Login or Register  to view this content.
    Actually, could you explain what the code is actually meant to do?

    Is it meant to save a specific worksheet from the workbook the code is in to a new workbook and add code from the original workbook to the new workbook?
    If posting code please use code tags, see here.

  5. #5
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: sheet not saving in correct filepath, instead its saving it to My Documents

    yes this statement is correct: Is it meant to save a specific worksheet from the workbook the code is in to a new workbook and add code from the original workbook to the new workbook?

    i have a workbook that contains multiple PO tabs. i need to save them as i use them. so when i put this in my code

    Please Login or Register  to view this content.
    and that code works, it saves it into the parent directory of the source file.

    but when i do that it fails here:

    Please Login or Register  to view this content.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: sheet not saving in correct filepath, instead its saving it to My Documents

    What exactly do you want/not want in the new 'PO' workbook(s)?

  7. #7
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: sheet not saving in correct filepath, instead its saving it to My Documents

    so the new workbook should contain just one PO, add code to it, add supporting sheets for the macro to run.

    the issue is where to put the "With ThisWorkbook" statements so that they work.

  8. #8
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: sheet not saving in correct filepath, instead its saving it to My Documents

    so i made a change to the code, it's failing on Workbooks("Purchase order-Template").Sheets("Formulas").Copy Before:=openworkbook.Sheets(1), gives me a run time error '91', object variable or with block variable not set

    Please Login or Register  to view this content.
    thoughts?

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,487

    Re: sheet not saving in correct filepath, instead its saving it to My Documents

    Probably missing something here, but the variable abc, as far as I can see contains a sheet name. Where do you add a file extension to the file name of the workbook?
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  10. #10
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: sheet not saving in correct filepath, instead its saving it to My Documents

    so i fixed it. made the following changes and now it is working as expected.

    Please Login or Register  to view this content.

  11. #11
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: sheet not saving in correct filepath, instead its saving it to My Documents

    Quote Originally Posted by TMS View Post
    Probably missing something here, but the variable abc, as far as I can see contains a sheet name. Where do you add a file extension to the file name of the workbook?
    the format is found on this line:

    Please Login or Register  to view this content.
    which saves it as a .xlsm format

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,487

    Re: sheet not saving in correct filepath, instead its saving it to My Documents

    Might save it with that format, but does it add the extension for you? I've always created the full file path, file name and file extension. Something I must try

    Thanks for the rep.

+ 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. VBA code not saving into FilePath
    By Keith Edgar in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-27-2014, 08:14 AM
  2. [SOLVED] Macro to save to Network Drive is saving to My Documents
    By MooseAUH in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-06-2014, 07:26 AM
  3. [SOLVED] Complex Parsing and Saving as Multiple Text Documents
    By johnph in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-29-2012, 04:13 PM
  4. Word not saving documents correctly
    By J.wills in forum Word Programming / VBA / Macros
    Replies: 5
    Last Post: 03-27-2009, 06:08 AM
  5. [SOLVED] saving documents with macros
    By shrek in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-10-2005, 06:20 PM
  6. [SOLVED] Saving New Documents on a network Drive.
    By MaxZ in forum Excel General
    Replies: 1
    Last Post: 11-09-2005, 06:35 PM
  7. Saving to users My Documents
    By Rob Edwards in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-24-2005, 06:07 AM
  8. Open documents interfering with saving
    By mgasparel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-14-2005, 05:26 PM

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