0
我從.xlsx創建一個.csv文件,所以我可以使用它從Scribe上傳到我的CRM。一切都很好,並且很棒,但是我的.xlsx文件在一些列中靜態地使用了100行的下拉列表。所以這個.csv文件有大約90行「,,,,,,」,我不希望它有。以下是我的腳本,它將此xlsx轉換爲csv,然後打開csv備份以刪除這些行並重新編寫.csv文件。唯一的問題是我無法重新打開文件,因爲我得到了拒絕權限的錯誤。OpenTextFile權限被拒絕
Set objArgs = CreateObject("Scripting.FileSystemObject")
objStartFolder = "C:\Users\bmckie\Documents\SugarSync Shared Folders\Janis Jarvis\CRM Import Spreadsheet"
Set objFolder = objArgs.GetFolder(objStartFolder)
Set colFiles = objFolder.Files
For Each objFile in colFiles
If UCase(objArgs.GetExtensionName(objFile.name)) = "XLSX" Then
Set objExcel = CreateObject("Excel.application")
objExcel.application.visible=false
objExcel.application.displayalerts=false
set objExcelBook = objExcel.Workbooks.Open(objStartFolder & "\" & objFile.Name)
newfile = objStartFolder & "\" & objArgs.GetBaseName(objFile.Name) & ".csv"
objExcelBook.SaveAs newfile, 23
Set objFile = objArgs.OpenTextFile(newfile, 1)
Do Until objFile.AtEndOfStream
strLine = objFile.Readline
secondLine = strLine
strLine = Replace(strLine, ",", "")
strLine = Replace(strLine, " ", "")
If Len(strLine) > 0 Then
strNewContents = strNewContents & secondLine & vbCrLf
End If
Loop
MsgBox(strNewContents)
objFile.Close
Set newobjFile = objArgs.OpenTextFile(newfile, 2)
newobjFile.Write strNewContents
newobjFile.Close
任何將.xlsx轉換爲.csv或具有權限問題的解決方案都將不勝感激。