提供一段VBA代碼供參考
創(chuàng)新互聯(lián)是一家網站建設、成都網站制作,提供網頁設計,網站設計,網站制作,建網站,按需求定制設計,網站開發(fā)公司,從2013年創(chuàng)立是互聯(lián)行業(yè)建設者,服務者。以提升客戶品牌價值為核心業(yè)務,全程參與項目的網站策劃設計制作,前端開發(fā),后臺程序制作以及后期項目運營并提出專業(yè)建議和思路。
作用是,保存當前工作簿的sheet,在當前文件夾下,單獨另存為xls文件
VB.NET與VBA有一些差別,自己調試一下改改。
Dim?TPath?As?String,?XSheet?As?Worksheet?
TPath?=?ActiveWorkbook.Path?
For?Each?XSheet?In?ActiveWorkbook.sheets?
XSheet.Copy?
ActiveWorkbook.SaveAs?Filename:=TPath??"\"??ActiveSheet.Name??".xls"?
ActiveWindow.Close?
Next
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'定義Word對象
Dim wordApp As New Word.ApplicationClass
'要轉換的文件名
Dim fileName As Object = "E:\Test.doc"
'默認值
Dim miss As Object = System.Reflection.Missing.Value
'打開要轉換的 DOC 文件
Dim doc As Word.Document = DirectCast(wordApp.Documents.Open(fileName, miss, miss, miss, miss, miss, _
miss, miss, miss, miss, miss, miss, _
miss, miss, miss, miss), Word.Document)
'轉換后的文件名
fileName = "E:\testDoc.HTML"
'保存的文件格式
Dim saveFormat As Object = Word.WdSaveFormat.wdFormatHTML
'按文本文件保存
doc.SaveAs(fileName, saveFormat, miss, miss, miss, miss, _
miss, miss, miss, miss, miss, miss, _
miss, miss, miss, miss)
'關閉是否保存文件,這里為不保存
Dim changes As Object = False
'關閉文件
doc.Close(changes, miss, miss)
'退出 Word 應用程序
wordApp.Quit(changes, miss, miss)
End Sub
Dim sFileName As String
Dim Search
Private Sub dateTimeMenu_Click()
Text1.Text = Now
End Sub
Private Sub deleteMenu_Click()
Text1.Text = Left(Text1.Text, Text1.SelStart) + Mid(Text1.Text, Text1.SelStart + Text1.SelLength + 1)
End Sub
Private Sub findMenu_Click()
Search = InputBox("請輸入要查找的字詞:")
Dim Where1 '獲取需要查找的字符串變量
Text1.SetFocus '文本框獲得焦點,以顯示所找到的內容Search = InputBox("請輸入要查找的字詞:")
Where1 = InStr(Text1.Text, Search) '在文本中查找字符串
If Where1 Then
'若找到則設置選定的起始位置并使找到的字符串高亮
Text1.SelStart = Where1 - 1
Text1.SelLength = Len(Search)
' Me.Caption = Where1 '測試用
'否則給出提示
Else: MsgBox "未找到所要查找的字符串。", vbInformation, "提示"
End If
End Sub
Private Sub findNextMenu_Click()
Dim Where2
Dim StartMe As Integer '查找的起始位置變量
Text1.SetFocus '文本框獲得焦點
StartMe = Text1.SelLength + Text1.SelStart + 1 '給變量賦值
Where2 = InStr(StartMe, Text1.Text, Search) '令其從上次找到的地方找起
If Where2 Then
Text1.SelStart = Where2 - 1
Text1.SelLength = Len(Search)
Else: MsgBox "未找到所要查找的字符串.", vbInformation, "提示"
End If
End Sub
Private Sub aboutMenu_Click()
MsgBox Space(2) "文本編輯器版本號1.0" Chr(13) "由西南財經大學天府學院" Chr(13) Space(5) "肖忠 開發(fā)" Chr(13) Space(2) "copyright:天府學院"
End Sub
Private Sub allMenu_Click()
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End Sub
Private Sub backcolorMenu_Click() '設置背景色代碼
Form1.CommonDialog1.Action = 3
Text1.BackColor = Form1.CommonDialog1.Color
End Sub
Private Sub colorMenu_Click() '改變文字顏色代碼
Form1.CommonDialog1.Action = 3
Text1.ForeColor = Form1.CommonDialog1.Color
End Sub
Private Sub cutMenu_Click()
Clipboard.SetText Text1.SelText
Text1.Text = Left(Text1.Text, Text1.SelStart) + Mid(Text1.Text, Text1.SelStart + Text1.SelLength + 1)
End Sub
Private Sub exitMenu_Click()
End
End Sub
Private Sub fontMenu_Click() '字體菜單代碼
Form1.CommonDialog1.Flags = 3 Or 256
Form1.CommonDialog1.Action = 4
If Len(Form1.CommonDialog1.FontName) = 0 Then
Form1.Text1.FontName = "宋體"
Else
Form1.Text1.FontName = Form1.CommonDialog1.FontName
End If
Form1.Text1.FontSize = Form1.CommonDialog1.FontSize
If Form1.CommonDialog1.FontBold = True Then
Form1.Text1.FontBold = True
Else
Form1.Text1.FontBold = False
End If
If Form1.CommonDialog1.FontItalic = True Then
Form1.Text1.FontItalic = True
Else
Form1.Text1.FontItalic = False
End If
Text1.ForeColor = Form1.CommonDialog1.Color
End Sub
Private Sub Form_Load()
Form1.Text1.Width = Form1.Width - 130
Form1.Text1.Height = Form1.Height
End Sub
Private Sub Form_Resize()
Form1.Text1.Width = Form1.Width - 130
Form1.Text1.Height = Form1.Height
End Sub
Private Sub help1Menu_Click()
Form1.CommonDialog1.HelpCommand = cdlHelpForceFile
Form1.CommonDialog1.HelpFile = "c:\windows\system32\winhelp.hlp"
CommonDialog1.ShowHelp
End Sub
Private Sub newMenu_Click()
If Len(Trim(Text1.Text)) = 0 Then
Form1.Caption = "我的記事本" "--" "未命名"
sFileName = "未命名"
Text1.FontSize = 15
Text1.FontName = "宋體"
Text1.Text = ""
Else
Call saveAsMenu_Click
Form1.Caption = "我的記事本" "--" "未命名"
sFileName = "未命名"
Text1.FontSize = 15
Text1.FontName = "宋體"
Text1.Text = ""
End If
End Sub
Private Sub openMenu_Click() '打開文件代碼
If Len(Trim(Text1.Text)) = 0 Then
Form1.Caption = "我的記事本"
Form1.CommonDialog1.Filter = "文本文件|*.txt"
Form1.CommonDialog1.Flags = 4096
Form1.CommonDialog1.Action = 1
If Len(Form1.CommonDialog1.FileName) 0 Then
sFileName = Form1.CommonDialog1.FileName
Form1.Caption = Form1.Caption "--" Form1.CommonDialog1.FileTitle
Open sFileName For Input As #1
Text1.FontSize = 15
Text1.FontName = "宋體"
Do While Not EOF(1)
Line Input #1, Text$
All$ = All$ + Text$ + Chr(13) + Chr(10)
Loop
Text1.Text = All
Close #1
End If
Else
Call saveAsMenu_Click
Form1.Caption = "我的記事本"
Form1.CommonDialog1.Filter = "文本文件|*.txt"
Form1.CommonDialog1.Flags = 4096
Form1.CommonDialog1.Action = 1
If Len(Form1.CommonDialog1.FileName) 0 Then
sFileName = Form1.CommonDialog1.FileName
Form1.Caption = Form1.Caption "--" Form1.CommonDialog1.FileTitle
Open sFileName For Input As #1
Text1.FontSize = 15
Text1.FontName = "宋體"
Do While Not EOF(1)
Line Input #1, Text$
All$ = All$ + Text$ + Chr(13) + Chr(10)
Loop
Text1.Text = All
Close #1
End If
End If
End Sub
Private Sub pasteMenu_Click() '粘貼菜單代碼
Text1.Text = Left(Text1.Text, Text1.SelStart) + Clipboard.GetText() + Mid(Text1.Text, Text1.SelStart + Text1.SelLength + 1)
End Sub
Private Sub printMenu_Click()
Form1.CommonDialog1.ShowPrinter
For i = 1 To CommonDialog1.Copies
Printer.Print Text1.Text
Printer.Print Text1.Text
Next
Printer.EndDoc
End Sub
Private Sub saveAsMenu_Click() '另存為菜單代碼
If Len(Trim(Text1.Text)) 0 Then
Form1.CommonDialog1.DialogTitle = "保存文件"
Form1.CommonDialog1.InitDir = "D:\"
Form1.CommonDialog1.Filter = "文本文件|*.txt"
Form1.CommonDialog1.Flags = 2
Form1.CommonDialog1.ShowSave
If Len(Form1.CommonDialog1.FileName) 0 Then
sFileName = Form1.CommonDialog1.FileName
Open sFileName For Output As #1
whole$ = Text1.Text
Print #1, whole
Close #1
End If
End If
End Sub
Private Sub saveMenu_Click()
If Len(Trim(Text1.Text)) 0 Then
Form1.CommonDialog1.DialogTitle = "保存文件"
Form1.CommonDialog1.InitDir = "D:\"
Form1.CommonDialog1.FileName = "新建文本"
Form1.CommonDialog1.Filter = "文本文件|*.txt"
Form1.CommonDialog1.Flags = 2
Form1.CommonDialog1.ShowSave
If Len(Form1.CommonDialog1.FileName) 0 Then
sFileName = Form1.CommonDialog1.FileName
Open sFileName For Output As #1
whole$ = Text1.Text
Print #1, whole
Close #1
End If
End If
End Sub
Private Sub statusMenu_Click()
End Sub
分享題目:vb點虐
另存為代碼 vbnet imports
標題來源:http://www.rwnh.cn/article42/ddgopec.html
成都網站建設公司_創(chuàng)新互聯(lián),為您提供、動態(tài)網站、網頁設計公司、做網站、網站制作、企業(yè)網站制作
聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)