我想在excel里用做个控件用VBA来把当前文件另存为一个txt文本,该txt文本的名字有固定格式,如补充中 5
1个回答
展开全部
'打开文件在菜单栏上有一个"保存TXT文件"按扭
Sub auto_open()
MenuBars(xlWorksheet).Reset
Set mycommandbar = CommandBars("standard")
Set mybutton = mycommandbar.Controls.Add(Type:=msoControlButton)
With mybutton
.Style = msoButtonCaption
.Caption = "保存TXT文件"
.Enabled = True
.OnAction = "SaveText"
End With
End Sub
Sub auto_close()
Set mycommandbar = CommandBars("standard")
For Each mybutton In mycommandbar.Controls
If mybutton.Caption = "保存TXT文件" Then mybutton.Delete
Next
End Sub
Sub SaveText()
Dim File As String
sj = Format(Now, "YYYYMMDDhhmm") & Int(Rnd() * 1000)
File = ThisWorkbook.Path & "\" & sj & ".txt"
On Error Resume Next
Kill File
Sheet1.Copy
ActiveWorkbook.SaveAs Filename:=File, FileFormat:=xlCSV
ActiveWorkbook.Close SaveChanges:=False
MsgBox "文件保存成功!"
End Sub
Sub auto_open()
MenuBars(xlWorksheet).Reset
Set mycommandbar = CommandBars("standard")
Set mybutton = mycommandbar.Controls.Add(Type:=msoControlButton)
With mybutton
.Style = msoButtonCaption
.Caption = "保存TXT文件"
.Enabled = True
.OnAction = "SaveText"
End With
End Sub
Sub auto_close()
Set mycommandbar = CommandBars("standard")
For Each mybutton In mycommandbar.Controls
If mybutton.Caption = "保存TXT文件" Then mybutton.Delete
Next
End Sub
Sub SaveText()
Dim File As String
sj = Format(Now, "YYYYMMDDhhmm") & Int(Rnd() * 1000)
File = ThisWorkbook.Path & "\" & sj & ".txt"
On Error Resume Next
Kill File
Sheet1.Copy
ActiveWorkbook.SaveAs Filename:=File, FileFormat:=xlCSV
ActiveWorkbook.Close SaveChanges:=False
MsgBox "文件保存成功!"
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询