+ Reply to Thread
Results 1 to 11 of 11

Macro to create documents by heading 1 worked and still does but suddenly with an error?

  1. #1
    Registered User
    Join Date
    04-02-2020
    Location
    London
    MS-Off Ver
    365
    Posts
    22

    Macro to create documents by heading 1 worked and still does but suddenly with an error?

    Hi All,

    I created this word macro a year or 2 ago. It worked perfectly for a year or so.

    It goes through the document and saves the text from heading 1 to just before the next heading 1 as a new document at the same location of the original file in a docx format.

    Suddenly, it still generates the documents but at the end i get this error.

    Run-time Rrror 5152
    This is not a Valid file name
    try one or more of the following
    *check the path to make sure it was typed correctly
    *Select a file from the list of files and folders


    The error is apparently on
    Please Login or Register  to view this content.
    This error sometimes suggests there are invalid characters in the filename, but i have checked and the only character used is - (hyphen) which is not invalid

    As i say it works but i get the above error. Can anyone help to resolve this?

    Please Login or Register  to view this content.

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Macro to create documents by heading 1 worked and still does but suddenly with an erro

    .
    See if adding these two lines of code does the job :

    Please Login or Register  to view this content.

  3. #3
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Macro to create documents by heading 1 worked and still does but suddenly with an erro

    Quote Originally Posted by benep123 View Post
    I created this word macro a year or 2 ago.
    No, you did not. You most likely lifted it from: https://www.msofficeforums.com/word-...save-file.html
    Last edited by macropod; 05-12-2020 at 09:27 AM.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

  4. #4
    Registered User
    Join Date
    04-02-2020
    Location
    London
    MS-Off Ver
    365
    Posts
    22

    Re: Macro to create documents by heading 1 worked and still does but suddenly with an erro

    ahhh you are right I did... to be honest i had forgotten - Thank you for your help at the time.... As the other person said, it has helped many people
    Last edited by benep123; 05-13-2020 at 04:37 AM. Reason: forgot to add something

  5. #5
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Macro to create documents by heading 1 worked and still does but suddenly with an erro

    Messing with Application.DisplayAlerts isn't likely to improve anything. The most likely issue is that the file you're processing hasn't ever been saved, so it doesn't have a valid path.

  6. #6
    Registered User
    Join Date
    04-02-2020
    Location
    London
    MS-Off Ver
    365
    Posts
    22

    Re: Macro to create documents by heading 1 worked and still does but suddenly with an erro

    Thanks @logit - i tried your suggestion. I added the
    Please Login or Register  to view this content.
    additions above i get
    Please Login or Register  to view this content.
    Thanks again for the original code @macropod. I tried adding
    Please Login or Register  to view this content.
    above .save2 as suggested in the referenced link, it performs the functions, and then crashes word. Only an End task in task manager get me out of it.

    The entire process completes, there are no other files to process, and the path is the root wherever the source document is.

  7. #7
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Macro to create documents by heading 1 worked and still does but suddenly with an erro

    Try:
    Please Login or Register  to view this content.
    Last edited by macropod; 05-13-2020 at 05:06 PM.

  8. #8
    Registered User
    Join Date
    04-02-2020
    Location
    London
    MS-Off Ver
    365
    Posts
    22

    Re: Macro to create documents by heading 1 worked and still does but suddenly with an erro

    Thanks. That also works but generates the same 5152 error at the end. Maybe i will just put up with it.

  9. #9
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Macro to create documents by heading 1 worked and still does but suddenly with an erro

    I cannot reproduce the 5152 error. Even an empty paragraph in the Heading 1 Style doesn't produce it (it produced a 4198 'Command failed' error instead).

  10. #10
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Macro to create documents by heading 1 worked and still does but suddenly with an erro

    .
    Posted in error.
    Last edited by Logit; 05-14-2020 at 12:34 PM.

  11. #11
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Macro to create documents by heading 1 worked and still does but suddenly with an erro

    .
    Macropod :

    Got your message.

    Hmmm ... my Alzheimers is acting up again ?

    Thanks

+ 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. error when running a macro to unsaved documents
    By chubbychub in forum Excel General
    Replies: 1
    Last Post: 01-06-2018, 08:51 PM
  2. Macro to create desktop shortcut. Worked, but saved sheet as template, now not.
    By thecdnmole in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-20-2014, 10:18 AM
  3. [SOLVED] Simple macro suddenly ends up with an error.
    By vin1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-03-2012, 06:56 AM
  4. Macro worked for 2 years, suddenly started giving strange results
    By dylanemcgregor in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-21-2009, 04:39 AM
  5. [SOLVED] Error with macro-it worked now it doesn't
    By Daniel R. Young in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-03-2005, 07:50 PM
  6. Error with macro-it worked now it doesn't
    By Daniel R. Young in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-02-2005, 06:17 PM
  7. Replies: 0
    Last Post: 05-18-2005, 05:06 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