抱歉英文不好
我可以保存Excel文件,但保存后,该文件包含所有图纸,不仅是“NaCl”,而且所有图纸都保存到新文件中。这是我的代码。
我想用单张纸张保存新文件。谢谢
Imports MySql.Data.MySqlClient
xlWorkBook = xlApp.Workbooks.Open("D:\งาน\งานโปรเจคปี 3\sa\Sourcecode_VB\project1\project1\excel\test_excel.xlsx")
xlWorkSheet = xlWorkBook.Sheets("NaCl")
With xlWorkSheet
'~~> Directly type the values that we want
.Range("D8").Value = "1"
.Range("D9").Value = "2"
End With
xlWorkBook.SaveAs(Filename:="D:\งาน\งานโปรเจคปี 3\sa\Sourcecode_VB\project1\project1\excel\test_excel1.xlsx", FileFormat:=51, _
ReadOnlyRecommended:=True, CreateBackup:=False)
答案 0 :(得分:0)
我只能使用原生VBE告诉解决方案。您需要删除工作表,确保更改保存路径。
Dim ws As Worksheet
Application.DisplayAlerts = False 'removes delete prompts
For Each ws In xlWorkBook.Worksheets
If ws <> xlWorkSheet Then ws.Delete 'deletes each worksheet that's not NaCl
Next
Application.DisplayAlerts = True