Paul Wagner
Registered User.
- Local time
- Yesterday, 16:14
- Joined
- May 18, 2004
- Messages
- 48
(Scroll to the bottom post for final answer & code)
I'm trying to piece together other techniques and here's what I have so far, but it's stuck on Excel reference in Shell (No Active X component). There's got to be a cleaner way to do this! HELP.
Public Sub ConvertCSVtoXL(strCSVPath As String)
Dim appExcel As Excel.Application
Dim Pathfile As String
'If Excel isn't running, start and activate it
If Err Then
Shell "c:\Program Files\Microsoft Office\Office11\Excel.exe"
AppActivate "Microsoft Excel"
End If
On Error GoTo 0
'Get an Application object so you can automate Excel.
Set appExcel = GetObject(, "Excel.Application")
Pathfile = Left(strCSVPath, Len(strCSVPath) - 3) & "xls"
With appExcel
.Workbooks.Open FileName:=strCSVPath
.ActiveWorkbook.SaveAs FileName:=Pathfile, FileFormat:=xlNormal
End With
'appExcel.Quit
'Set appExcel = Nothing
MsgBox "File '" & strCSVPath & "' has been converted to excel under the same " & _
"filename with an XLS extension"
End Sub
I'm trying to piece together other techniques and here's what I have so far, but it's stuck on Excel reference in Shell (No Active X component). There's got to be a cleaner way to do this! HELP.
Public Sub ConvertCSVtoXL(strCSVPath As String)
Dim appExcel As Excel.Application
Dim Pathfile As String
'If Excel isn't running, start and activate it
If Err Then
Shell "c:\Program Files\Microsoft Office\Office11\Excel.exe"
AppActivate "Microsoft Excel"
End If
On Error GoTo 0
'Get an Application object so you can automate Excel.
Set appExcel = GetObject(, "Excel.Application")
Pathfile = Left(strCSVPath, Len(strCSVPath) - 3) & "xls"
With appExcel
.Workbooks.Open FileName:=strCSVPath
.ActiveWorkbook.SaveAs FileName:=Pathfile, FileFormat:=xlNormal
End With
'appExcel.Quit
'Set appExcel = Nothing
MsgBox "File '" & strCSVPath & "' has been converted to excel under the same " & _
"filename with an XLS extension"
End Sub
Last edited: