好吧我試圖編寫一個宏,將excel工作簿保存到csv文件中。我已經嘗試了許多不同的解決方案,但我仍然遇到問題需要正確打印值。當我打開它產生的文件。我遺漏的所有代碼剩下的部分是將原始電子表格複製到臨時表單中,這樣我就可以從同一個WB中取出多個表單並將它們打印到同一個csv文件中。它還有一個模塊,可以清除該臨時文件的所有格式和內容。我跑的代碼,只需將它打印到一個新的Excel電子表格和它工作得很好,爲什麼csv從excel錯誤輸出,但其他數據類型正常工作?
出來放像這樣就不會打印到不知道一個CSV:
K ! bîh^ [Content_Types].xml ¢(
[… skip a bunch of binary lines …]
KÆ8k¡~¥-ÙÔäá ûÜ
我的代碼如下所示:
Sub SaveFile()
Dim NewName As String
Dim nm As Name
Dim ws As Worksheet
If MsgBox("Copy specific sheets to a new workbook" & vbCr & _
"New sheets will be pasted as values, named ranges removed" _
, vbYesNo, "NewCopy") = vbNo Then Exit Sub
With Application
.ScreenUpdating = False
' Copy specific sheets
' *SET THE SHEET NAMES TO COPY BELOW*
' Array("Sheet Name", "Another sheet name", "And Another"))
' Sheet names go inside quotes, seperated by commas
On Error GoTo ErrCatcher
Sheets(Array("Raw Data Copy")).copy
On Error GoTo 0
' Paste sheets as values
' Remove External Links, Hperlinks and hard-code formulas
' Make sure A1 is selected on all sheets
For Each ws In ActiveWorkbook.Worksheets
ws.Cells.copy
ws.[A1].PasteSpecial Paste:=xlValues
ws.Cells.Hyperlinks.Delete
Application.CutCopyMode = False
Cells(1, 1).Select
ws.Activate
Next ws
Cells(1, 1).Select
' Remove named ranges
For Each nm In ActiveWorkbook.Names
nm.Delete
Next nm
' Input box to name new file
NewName = "test"
' Save it with the NewName and in the same directory as original
ActiveWorkbook.SaveCopyAs ThisWorkbook.path & "\" & NewName & ".csv"
ActiveWorkbook.Close SaveChanges:=False
.ScreenUpdating = True
End With
Exit Sub
ErrCatcher:
MsgBox "Specified sheets do not exist within this workbook"
End Sub
如果我使用SaveAs方法,我可以將位置保存到etl服務器還是必須是本地? – user3753693