1

Have a need to automate conversion of CSV files to XLS. The CSV files (which contain text qualifiers) will be automatically downloaded from a SFTP site and pushed to fixed width files for AS400 integration. The customer currently has someone manually log into SFTP site, download file(s), open in Excel and save as XLS. They have no control of original format or naming so the script must be able to convert files regardless of file name and/or number of files. Am looking to automate the manual process or remove text qualifiers to help manage column mapping discrepancy. Any advice would be greatly appreciated!

The customer uses SSIS as their development tool. I apologize if the post is not clear. Am a newbie. Thanks!

4

1 回答 1

2

看起来你正在寻找这样的东西:

Sub SaveAsXLSX()

Dim wbSource As Workbook
Dim vrtSelectedItem As Variant

'Allows you to pick the CSV file from wherever it's been saved.
With Application.FileDialog(msoFileDialogOpen)
    .InitialFileName = "C:\Users\YourUsername\Documents" & "\"
    .AllowMultiSelect = False
    .Show
        For Each vrtSelectedItem In .SelectedItems
            Set wbSource = Workbooks.Open(vrtSelectedItem)
        Next
End With

'Saves the file as an .xlsx file.
wbSource.SaveAs Filename:="Random Name.xlsx", FileFormat:=51

End Sub

只需记住将 更改为.InitialFileName保存这些下载的任何位置的文件路径。

于 2013-07-29T20:34:58.963 回答