Consulting

Results 1 to 3 of 3

Thread: How to Save File & Overwrite Original??

  1. #1
    VBAX Expert
    Joined
    Aug 2007
    Location
    Windermere, FL, a 'burb in the greater Orlando metro area.
    Posts
    567
    Location

    How to Save File & Overwrite Original??

    Hi, All,

    I want to open a tab-delimited text file (info.txt), do some manipulations using VBA, and then save the file back as tab-delimited text using the same name.

    Using Macro Recorder to get a jumping off point, I ended up with this for opening and saving:
    [vba]Sub Macro1()
    '
    ' Macro1 Macro
    '
    Workbooks.OpenText Filename:="C:\Users\Ron\Desktop\EV Check6\INFO.TXT", _
    Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
    xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
    Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
    Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), _
    Array(9, 1)), TrailingMinusNumbers:=True

    ActiveWorkbook.SaveAs Filename:="C:\Users\Ron\Desktop\EV Check6\INFO.TXT", _
    FileFormat:=xlText, CreateBackup:=False

    End Sub
    [/vba]
    The only problem: when I run the macro, Excel pops a dialog telling me the file exists and asking if I want to replace it.

    How do I get Excel/VBA to just save it, ever so quietly? I answered Yes when I originally saved the file while recording the macro; why was that action not recorded in the macro?

    Thanks!
    Ron
    Windermere, FL

  2. #2
    VBAX Regular HaHoBe's Avatar
    Joined
    Aug 2004
    Location
    Hamburg
    Posts
    89
    Location
    Hi, Ron,

    [VBA]With Application
    .DisplayAlerts = False
    ActiveWorkbook.SaveAs FileName:="C:\Users\Ron\Desktop\EV Check6\INFO.TXT", _
    FileFormat:=xlText, CreateBackup:=False
    .DisplayAlerts = True
    End With[/VBA]
    Ciao,
    Holger

  3. #3
    VBAX Regular
    Joined
    Jun 2007
    Posts
    69
    Location
    Holger,

    Thank you very much. I've been away from VBA for 4 or 5 months and my little gray cells have forgotten much.

    Thanks,
    Ron McKenzie
    Windermere, FL
    (living in the huge shadow of a tiny rodent)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •