我有這個腳本,我想另外保存爲一個xls文件,也保存爲一個.txt在相同的目錄,甚至不同的。我可以在這裏得到一些指導嗎?Excel保存爲TXT文件
Imports System.IO
Module Module1
Private Property fs As Object
Private Property BaseName As Object
Private Property FullTargetPath As Object
Sub Main()
Dim targetfolder As String = "C:\TEST"
Dim sourcefolder As String = "\\10.97.8.16\c$\Checks\XMLFiles"
Dim Searchpattern As String = String.Format("{0:MM-dd-yyyy}*.xml", Date.Today)
Dim todaysfiles() As String = Directory.GetFiles(sourcefolder, Searchpattern)
Dim xlApp, xlWkb
xlApp = CreateObject("excel.application")
fs = CreateObject("Scripting.FileSystemObject")
Const xlnormal = 1
'Extra Dims
'Hide Excel
xlApp.Visible = False
For Each file As String In todaysfiles
' Excel stuff... '
Dim fileName As String = IO.Path.GetFileNameWithoutExtension(file)
' Concatenate full path. Extension will be automatically added by Excel. '
Dim fullTargetPath = IO.Path.Combine(targetfolder, fileName)
'Process each file in SourceFolder
' For Each file In fs.GetFolder(SourceFolder).files
'Open file in SourceFolder
xlWkb = xlApp.Workbooks.Open(file)
'Get Filename
BaseName = fs.getbasename(file)
'Concatenate full path. Extension will be automatically added by Excel
fullTargetPath = targetfolder & "\" & BaseName
'Save as XLS file into TargetFolder
xlWkb.SaveAs(fullTargetPath, xlnormal)
'Close the file after its done
xlWkb.close()
Next
xlWkb = Nothing
xlApp = Nothing
fs = Nothing
' MsgBox("Thank you. Currently the Date is: " & Date.Today & " people like to eat chicken Every " & Date.Today.Ticks & " minutes.")
'This is for extra code below
End Sub
前端模塊
嗨雨果, 改變,以及常量xltext = 1,仍然將其更改爲xls文件,而不是txt文件。 – GabrielVa 2010-08-31 12:29:10
xlText doens't等於1 ...在這裏讓我看看。 xlText是一個像xlnormal一樣的全局vba常量。 xlText等於-4158,xlNormal等於-4143,如果你堅持使用幻數。 – Hugo 2010-08-31 13:15:03
嗯,intresting足夠我設置爲常量xltext = 1,它做了轉換爲xls。我將它更改爲-4158,並將其轉換爲文本文件,但現在要求我每次將它保存爲它之前的位置。我已將它設置爲xlweb.close()。 – GabrielVa 2010-08-31 13:50:03