+ Reply to Thread
Results 1 to 4 of 4

Saving as Filename

  1. #1
    Forum Contributor
    Join Date
    04-30-2004
    Posts
    122

    Saving as Filename

    I have written a code which opens a text file, puts the text in columns, and formats certain cells, then saves the file as an excel type file. At the end of this code, I want to open a saveas dialog box and automatically put the name of the file in the FileName box. However, when I do this, it puts the file as " "filename.txt" " in the file name box. I want it to just say " filename ".

    Here's the code....

    FName = Application.GetOpenFilename("Text Files (*.txt), *.txt")
    If FName <> False Then
    Workbooks.OpenText Filename:= _
    FName, Origin:=xlWindows, _
    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), _
    Array(10, 1), Array(11, 1), Array(12, 1))
    ElseIf FName = Flase Then
    End
    End If

    <Here is where I put all the code for the formatting>

    fileSaveName = Application.GetSaveAsFilename( _
    InitialFilename:=FName, _
    fileFilter:="Microsoft Excel Files (*.xls), *.xls")
    If fileSaveName <> False Then
    ActiveWorkbook.Save
    ElseIf fileSaveName = False Then
    End If

    .....


    Does anyone know what I'm doing wrong?

  2. #2
    Forum Contributor
    Join Date
    04-30-2004
    Posts
    122
    Basically what I'm trying to do is get the name of the original .txt file in the file name box without the file extention (.txt). Is that more clear?

  3. #3
    Forum Contributor
    Join Date
    11-09-2004
    Posts
    451

    Saving as Filename

    try this macro

    no change,just retrieved the filename without the extension and put it in
    GetSaveAsFilename method



    Sub macro()
    FName = Application.GetOpenFilename("Text Files (*.txt), *.txt")
    If FName <> False Then
    Workbooks.OpenText Filename:= _
    FName, Origin:=xlWindows, _
    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), _
    Array(10, 1), Array(11, 1), Array(12, 1))
    ElseIf FName = Flase Then
    End
    End If
    Dim t As Variant
    t = Split(FName, ".txt")

    fileSaveName = Application.GetSaveAsFilename( _
    InitialFilename:=t(0), _
    fileFilter:="Microsoft Excel Files (*.xls), *.xls")
    If fileSaveName <> False Then
    ActiveWorkbook.Save
    ElseIf fileSaveName = False Then
    End If

    End Sub

  4. #4
    Forum Contributor
    Join Date
    04-30-2004
    Posts
    122
    Thanks! That was what I was looking for. I got it to work by putting in another line of code which takes away the extention.

    FName =activeworksheet.name
    SaveName = left(FName,len(FName)-4)

    But the way you did it is much cleaner.

    Thanks again!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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