+ Reply to Thread
Results 1 to 5 of 5

Create a Text File and then Append Text

  1. #1
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Create a Text File and then Append Text

    Office 2016
    The following works perfectly if the text file already exists. If the program has to create the text file, then I get a "Permission Denied" Error on the Open PathName ... line.

    I want the program to check to see if the file exists. If it does not, then create the file and append the text. Somehow, I have to close out the file I just created so I can open it again. That is the syntax I can't seem to find.

    Second question: on my Office 2013 system I get a 429 Error - Active X component can't create object on the first Set fso = CreateObject("Scripting.FileSystemObject") - why this error in 2013 and not in 2016?

    To test, run the Executive macro.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  2. #2
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Create a Text File and then Append Text

    You need to add:

    Please Login or Register  to view this content.
    before you can open it with the Open statement, though I don't know why you wouldn't just write to it while it's open.
    Rory

  3. #3
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Create a Text File and then Append Text

    Yeah, I just found that myself.

    Yes, I could write to it but then I'd also have to close it. I got lazy and just decided to let the execution "fall through."

    Thanks for your help.

  4. #4
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Create a Text File and then Append Text

    I'd also point out that Open will create it if it doesn't exist if you open it for appending.

  5. #5
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Create a Text File and then Append Text

    I did not know that! This means that my test, creation and closing of the file is unnecessary.

    It won't hurt to keep it in there, so I won't change my legacy code until I work with it again. I fixed it for all programs going forward.

+ 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. [SOLVED] Import and append data from the text file into worksheet, starting at a specific row.
    By excelicus in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-09-2018, 02:04 AM
  2. [SOLVED] Create text file based off of common text in column A with data in columns B-F
    By BG1983 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-14-2016, 12:47 PM
  3. Create text file from excel and use a cell value as text file name
    By tk636 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-27-2014, 06:47 PM
  4. [SOLVED] Macro to create text file and write contents of selected cells to the file
    By m@cro in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-13-2013, 10:21 AM
  5. Count Number Of lines in text files and append values to beginning of file
    By motoxeryz125 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-27-2011, 11:14 PM
  6. looping, Open text file, copy text, close text file
    By jwilds1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-18-2009, 05:12 PM
  7. [SOLVED] Append Records to a Text File
    By Randy in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-03-2005, 02:45 AM

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