vb.net另存为代码 vb另存为程序怎么写

VB.NET 控制EXCEL中的某几个sheet 到另外一个新的EXCEL文档中,并保存为单独文件 。有EXCEL 类 。求丰满提供一段VBA代码供参考
作用是vb.net另存为代码,保存当前工作簿的sheetvb.net另存为代码,在当前文件夹下vb.net另存为代码,单独另存为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
vb.net中datagradview 另存为excel文件的问题Public Class Cls导入数据
Dim xlApp As New Excel.Application()
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim A = "A"
Public Function 导出到Excel(ByVal Dt表 As DataTable) As Boolean
Dim rowIndex, colIndex As Integer
rowIndex = 1
colIndex = 0
xlBook = xlApp.Workbooks().Add
xlSheet = xlBook.Worksheets("sheet1")
Dim Table As New DataTable()
Table = CreaTable()
'将所得到的表的列名,赋值给单元格
Dim Col As DataColumn
Dim Row As DataRow
For Each Col In Table.Columns
colIndex = colIndex1
xlApp.Cells(1, colIndex) = Col.ColumnName
Next
'得到的表所有行,赋值给单元格
For Each Row In Table.Rows
rowIndex = rowIndex1
colIndex = 0
For Each Col In Table.Columns
colIndex = colIndex1
xlApp.Cells(rowIndex, colIndex) = Row(Col.ColumnName)
Next
Next
With xlSheet
.Range(.Cells(1, 1), .Cells(1, colIndex)).Font.Name = "黑体"
'设标题为黑体字
.Range(.Cells(1, 1), .Cells(1, colIndex)).Font.Bold = True
'标题字体加粗
.Range(.Cells(1, 1), .Cells(rowIndex, colIndex)).Borders.LineStyle = 1
'设表格边框样式
End With
With xlSheet.PageSetup
.LeftHeader = ""Chr(10)"""楷体_GB2312,常规""10公司名称:"'Gsmc
.CenterHeader = """楷体_GB2312,常规""公司人员情况表""宋体,常规"""Chr(10)"""楷体_GB2312,常规""10日 期:"
.RightHeader = ""Chr(10)"""楷体_GB2312,常规""10单位:"
.LeftFooter = """楷体_GB2312,常规""10制表人:"
.CenterFooter = """楷体_GB2312,常规""10制表日期:"
.RightFooter = """楷体_GB2312,常规""10第P页 共N页"
End With
xlApp.SaveWorkspace()
MsgBox("保存完毕", MsgBoxStyle.Exclamation, "提示")
KillAllExcels()
'xlApp.Visible = True
End Function
Sub KillAllExcels()
Dim proc As System.Diagnostics.Process
For Each proc In System.Diagnostics.Process.GetProcessesByName("EXCEL")
proc.Kill()
Next
End Sub
end class
用vb.net编写记事本源代码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.SelStartText1.SelLength1)
End Sub
Private Sub findMenu_Click()
Search = InputBox("请输入要查找vb.net另存为代码的字词:")
Dim Where1 '获取需要查找的字符串变量
Text1.SetFocus '文本框获得焦点vb.net另存为代码,以显示所找到的内容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.SelLengthText1.SelStart1 '给变量赋值
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)"肖忠 开发"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.SelStartText1.SelLength1)
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
【vb.net另存为代码 vb另存为程序怎么写】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 = "vb.net另存为代码我的记事本""--""未命名"
sFileName = "未命名"
Text1.FontSize = 15
Text1.FontName = "宋体"
Text1.Text = ""
Else
Call saveAsMenu_Click
Form1.Caption = "vb.net另存为代码我的记事本""--""未命名"
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.SelStartText1.SelLength1)
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.net编写写字板时怎么实现保存与另存为可以用SaveFileDialog1对话框加上对文件数据操作的类来实现,,用richtextbox自己的属性方法也能行!我以前做过一个记事本程序就是那样的!
VB,NET 如何把WORD另存为HTMLPrivate 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
vb.net对一个已存在的EXCEL操作怎么做到写入数据后在原文件中保存当前的数据这个应该版本比较高吧,我的2003下 , application没有save方法 。你现在保存的是application,不是单独一个工作簿 , 2003版本下,单独保存一个工作簿是不会提示的 , 你试试单独保存工作簿,要引用一个workbook对象 。
或则看看save方法是否有参数,可以避免弹出提示框 。
关于vb.net另存为代码和vb另存为程序怎么写的介绍到此就结束了 , 不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息 , 记得收藏关注本站 。

    推荐阅读