PDA

View Full Version : Solved: Change code to choose .txt file already open



Meatball
06-21-2010, 09:10 AM
I am converting text files that are e-mailed to me into Excel. The conversion works fine but instead of saving the files and then going to find them I would like to open them from the e-mail, convert to .xls, save the .xls and discard the .txt file. So I would like this part of the code "ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;Y:\Gould Southern Info\GA Kits\P.O. Assigned (Ordered) Kits\GA 2947--RFQ 22506 BOEING-STRUCTURES 6-14-10\SUMMARY FOR TK\OrderSum 2960.TXT" _
, Destination:=Range("$A$1")) ] to choose the already open file. I did a search and tried using the recorder but to no avail. This is the full codeSub Macro1()
'
' Macro1 Macro
'
'
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;Y:\Gould Southern Info\GA Kits\P.O. Assigned (Ordered) Kits\GA 2947--RFQ 22506 BOEING-STRUCTURES 6-14-10\SUMMARY FOR TK\OrderSum 2960.TXT" _
, Destination:=Range("$A$1"))
.Name = "OrderSum 2960"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 1252
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub

Thanks for any help

Bob Phillips
06-21-2010, 10:15 AM
You have to email attachments from th HDD, so why not just save them as Excel files to a temp directory, attach them all to the email, then Kill them?

Meatball
06-21-2010, 11:03 AM
I may not have been quite clear or I am not understanding what you are saying
The .txt files are e-mailed to me. I want to open them from the e-mail, convert and save. Another option would be to save all .txt files in the e-mail to a folder and convert the whole folder but I am not sure if I can then finish the code that will save the .xls files as I want to. I know I can write the code to save them if I work them directly from the e-mail 1 at a time.

Bob Phillips
06-21-2010, 12:06 PM
I know I can write the code to save them if I work them directly from the e-mail 1 at a time.

So what do you need from us?

Meatball
06-21-2010, 12:18 PM
The code as I have it makes you choose a file from a folder to open and convert. I want it to convert a file which is already open.

Meatball
06-21-2010, 01:12 PM
The final format needed has been changed. I probably do not need to get the code changed as requested. Thanks for looking at it anyway.