HELP! Programmicly Save an Excel File ?

M

meyvn77

I am exporting data from a GIS application to Excel.

I am currently just opening a tab delimited file in excel.
The file that opens is somename.txt but it is in excel. To accually get
an 'excel' file the user must do a save as .xls.

I would like to save the somename.txt as somename.xls to take that step
out or the operation. I would also like the excel file so I can
manipulate it and create some new worksheets and compile some simple
statistics.

Current Code:
Open filepath_Export & "Selection_Set.txt" For Output As #1
Print #1, strHeaderRow & vbCr & sData
Close #1

'Open the new text file in Excel
Shell GetAssociatedExecutable(".xls") & " " & _
Chr(34) & filepath_Export & "Selection_Set.txt" &
Chr (34), vbNormalFocus

Some code here to save the file or active window file or
something


Thanks,

Charles
 
M

meyvn77

Solved my own problem

Solution.. Record a macro and stick it on a button.

Dim plGetPathString As String
Dim filepath As String

plGetPathString = ""
filepath = Trim$(ActiveWorkbook.FullName)

While InStr(filepath, "\")
plGetPathString = plGetPathString & Left$(filepath,
InStr(filepath, "\"))
filepath = Mid$(filepath, InStr(filepath, "\") + 1)
Wend
If Len(Dir("" & plGetPathString & "Selection_Set.xls")) > 1 Then
'MsgBox "file exists"
ActiveWorkbook.SaveAs Filename:="" & plGetPathString &
"Selection_Set_" & Rnd() & ".xls", FileFormat _
:=xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:= _
False, CreateBackup:=False, Accessmode:=xlNoChange,
ConflictResolution:=xlUserResolution
Else
ActiveWorkbook.SaveAs Filename:="" & plGetPathString &
"Selection_Set.xls", FileFormat _
:=xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:= _
False, CreateBackup:=False, Accessmode:=xlNoChange,
ConflictResolution:=xlUserResolution
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top