Results 1 to 6 of 6

Executing a SaveAs Command in an Open .txt File

Threaded View

HannahTee Executing a SaveAs Command in... 12-17-2013, 05:06 PM
6StringJazzer Re: Executing a SaveAs... 12-17-2013, 06:12 PM
HannahTee Re: Executing a SaveAs... 12-17-2013, 06:22 PM
6StringJazzer Re: Executing a SaveAs... 12-17-2013, 08:16 PM
HannahTee Re: Executing a SaveAs... 12-18-2013, 03:48 PM
6StringJazzer Re: Executing a SaveAs... 12-18-2013, 10:57 PM
  1. #1
    Registered User
    Join Date
    12-11-2013
    Location
    Chicago
    MS-Off Ver
    Excel 2003
    Posts
    3

    Executing a SaveAs Command in an Open .txt File

    Hello!

    I'm writing a Macro that writes the contents of the cells in the first column of a worksheet into an already existing .txt file on my desktop. All of that is working fine and dandy until I want to save the .txt file under a new name (See bolded code below). I'm getting an Object Required Error, probably because my syntax is incorrect. Anyone have any helpful corrections?

    Thank you!!

        Sheets("Blank").Select
        Range("A1").Select
        Selection.pastespecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
        Dim r As Integer
        Open "Macintosh HD:Users:Name:Desktop:trial.txt" For Output As #1
            Sheets("Blank").Activate
               ii = Sheets("Blank").Cells(Rows.Count, 1).End(xlUp).Row
                For r = 1 To ii
                    data = Cells(r, 1)
                        Print #1, data
                Next r
            ActiveDocument.SaveAs Filename:="NewDocument.txt", _
            FileFormat:=wdFormatText
    
        Close
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you since it's your first post. --6SJ
    Last edited by HannahTee; 12-18-2013 at 03:49 PM. Reason: code tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Problem With Open File and Save File With Saveas and then close the File
    By John Vieren in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-27-2013, 12:53 AM
  2. [SOLVED] Open and SaveAs an .xlsx file to a .csv
    By DJBittner in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-25-2012, 03:15 PM
  3. Open file after workbook executing code is closed
    By randell.graybill in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-13-2011, 10:05 PM
  4. Macro: SaveAs: how to keep file open after saved?
    By trillium in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-08-2010, 04:38 PM
  5. [SOLVED] Open Excel with a XML file and SaveAs XLS
    By Li Pang in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-03-2006, 05:20 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