Results 1 to 3 of 3

Thread: [RESOLVED] Saving text file without prompt

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    2

    Resolved [RESOLVED] Saving text file without prompt

    I am opening a text file in Excel, making some changes to it, and trying to save it back in .txt format.
    The problem is that I keep getting 2 user prompt boxes.
    The first comes at the SaveAs command. It says "<filename> already exists. Do you want to replace it?

    Then, when I try to close the worksheet, I get another box that says "Not in Excel Format. Do you want to Save". If I say 'Yes', then I get the whole Filename prompt box and I'm not even in the directory that I want to save it in.

    How do I avoid these prompts?


    Here is the code I am using

    srcFolder = "C:\Scripts"
    srcFilename = "spr_bat.txt"
    Application.ScreenUpdating = False
    ChDir (srcFolder)
    Workbooks.OpenText FileName:=srcFolder + "\" + srcFilename, Origin:=xlWindows, _
    StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
    ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False, Comma:=True _
    , Space:=False, Other:=False, FieldInfo:=Array(Array(1, 2), Array(2, 1), _
    Array(3, 3), Array(4, 1), Array(5, 1))
    '
    '
    ' < Here I have a lot of code making changes to the file>
    '
    '
    ChDir (srcFolder)
    ActiveWorkbook.SaveAs FileName:=srcFolder + "\" + srcFilename, FileFormat:=xlText, _
    CreateBackup:=False
    ChDir (objfolder)
    ActiveWindow.Close ' This is where I get the not in Excel Format box

  2. #2
    Lively Member
    Join Date
    Jun 2005
    Posts
    112

    Re: Saving text file without prompt

    Change as follows:

    VB Code:
    1. ChDir (srcFolder)
    2. [COLOR=Red]Application.DisplayAlerts = False[/COLOR]
    3. ActiveWorkbook.SaveAs FileName:=srcFolder + "\" + srcFilename, FileFormat:=xlText, _
    4. CreateBackup:=False
    5. ChDir (objfolder)
    6. ActiveWindow.Close ' This is where I get the not in Excel Format box
    7. [COLOR=Red]Application.DisplayAlerts = True[/COLOR]

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2005
    Posts
    2

    Re: Saving text file without prompt

    I could have sworn that I tried the DisplayAlerts before, but you are right. It seems to be working now. Thank You.

Posting Permissions

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



Click Here to Expand Forum to Full Width