:
Sub Rectangle1_Click()
Application.DisplayAlerts = False
' Save file name and path into a variable
template_file = ActiveWorkbook.FullName
' Default directory would be c:\temp. Users however will have the ability
' to change where to save the file if need be.
fileSaveName = Application.GetSaveAsFilename(_
InitialFileName:="C:\users\%username%\SNSCA_Customer_" + _
VBA.Strings.Format(Now, "mmddyyyy") + ".txt", _
fileFilter:="Text Files (*.txt), *.txt")
If fileSaveName = False Then
Exit Sub
End If
' Save file as .txt TAB delimited fileSaveName, FileFormat:=36,
ActiveWorkbook.SaveAs Filename:= _
fileSaveName, FileFormat:=xlTextWindows, _
CreateBackup:=False
file_name_saved = ActiveWorkbook.FullName
MsgBox "Your SNSCA configuration upload file has been " _
& "successfully created at: " & vbCr & vbCr & file_name_saved
End Sub
편집 ... 여기
중 하나를 작동하지 않는 대안이다 아래 VBA를 사용하여 txt 파일의 마지막 줄을 지울 수 있습니다 (이 방법으로 저장하면 빈 줄이 기록됨).
이 VBA는 일반적으로 사용되는 vbscript 루틴을 기반으로합니다. 그것은
Sub Rectangle1_Click()
Dim strTemplateFile As String
Dim strFname As String
Dim strFnameClean As String
Dim FileSaveName
Application.DisplayAlerts = False
' Save file name and path into a variable
strTemplateFile = ActiveWorkbook.FullName
' Default directory would be c:\temp. Users however will have the ability
' to change where to save the file if need be.
FileSaveName = Application.GetSaveAsFilename(_
InitialFileName:="C:\users\%username%\SNSCA_Customer_" + _
VBA.Strings.Format(Now, "mmddyyyy") + ".txt", _
fileFilter:="Text Files (*.txt), *.txt")
If FileSaveName = False Then
Exit Sub
End If
' Save file as .txt TAB delimited fileSaveName, FileFormat:=36,
ActiveWorkbook.SaveAs Filename:= _
FileSaveName, FileFormat:=xlTextWindows, _
CreateBackup:=False
strFname = ActiveWorkbook.FullName
strFnameClean = Replace(ActiveWorkbook.FullName, ".txt", "clean.txt")
MsgBox "Your SNSCA configuration upload file has been " _
& "successfully created at: " & vbCr & vbCr & strFname
Call Test(strFname, strFnameClean)
End Sub
Sub Test(ByVal strFname, ByVal strFnameClean)
Const ForReading = 1
Const ForWriting = 2
Dim objFSO As Object
Dim objTF As Object
Dim strAll As String
Dim varTxt
Dim lngRow As Long
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTF = objFSO.OpenTextFile(strFname, ForReading)
strAll = objTF.readall
objTF.Close
Set objTF = objFSO.createTextFile(strFnameClean, ForWriting)
varTxt = Split(strAll, vbCrLf)
For lngRow = LBound(varTxt) To UBound(varTxt) - 1
objTF.writeline varTxt(lngRow)
Next
objTF.Close
End Sub
는 엑셀 문서. 그러나 저장 후 즉시 파일을 읽고 여분의 줄을 제거 할 수 있습니다. –
다른 스크립트가 너무 민감하다고 말하고 싶습니다 ... 뒤의 빈 줄에 숨 막히지 않도록 변경하십시오! –
VBA가 활성 워크 시트를 내보내는 방식을 변경하려고 시도했지만 작동하지 않는 것 같습니다. 위의 내용에서 saveas와 같은 활성 워크 시트의 모든 내용을 저장하기 위해 exporttxt 변수를 가져올 수 없습니다. – user1132827