vba转换vb.net6 vba和vbnet
excelVBA代码转化成可以在VB里运行的代码
你的这段代码只是通过运行特定的工作簿,来打开隐藏在系统文件夹的某个Excel文件。如果通过VB来打开该文件。那么前面的Protect部分意义不大。给你全部修改掉,直接通过VB来核对密码:
创新互联公司主要从事成都做网站、成都网站建设、成都外贸网站建设、网页设计、企业做网站、公司建网站等业务。立足成都服务云霄,10年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18982081108
代码如下:
Private Sub Command1_Click()
Dim ss As String, n As Integer
Do While True
ss = InputBox("请输入授权密码:", "查看权限")
If ss = "123456" Then Exit Do
n = n + 1
If n = 3 Then GoTo 200
Loop
Dim xlApp As Object
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
xlApp.Workbooks.Open ("C:\WINDOWS\system32\drivers\n.xls")
Exit Sub
200:
MsgBox "对不起,您已经三次输错密码,系统将自动退出。" vbCrLf _
"如果要获得文件权限,请与管理员联系!", vbOKOnly + vbExclamation
End Sub
如何vb转换到vb.net
你可以直接打开 VB6 的程序,VB.net 会自动启动升级向导将你的 VB6 代码升级为 VB.net。
您好请问如何将vba改成vb.net呢?谢谢啦) Dim swApp As Object Dim Part As Object Dim boolstatus As Boo
swApp.ActiveDoc是什么东西?word的吗?
如果是ord的东西,那么将set去掉就可以了,其他的不需要做任何更改。
vba代码转换成vb代码
由于不清楚这段VBA代码的具体含义,所以只是大概转换了一下,不知道能否运行。
'在VB中运行前需勾选"工程"-"引用"-"Microsoft Word 11.0 Object Library"
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Set wdApp = New Word.Application
Set wdDoc = wdApp.Documents.Add
wdApp.ChangeFileOpenDirectory "E:\毕设1\"
wdApp.Selection.InsertFile FileName:="1.doc", Range:="", ConfirmConversions:= _
False, Link:=False, Attachment:=False
wdApp.Selection.InsertFile FileName:="2.doc", Range:="", ConfirmConversions:= _
False, Link:=False, Attachment:=False
wdApp.Selection.InsertFile FileName:="3.doc", Range:="", ConfirmConversions:= _
False, Link:=False, Attachment:=False
wdApp.Selection.InsertFile FileName:="4.doc", Range:="", ConfirmConversions:= _
False, Link:=False, Attachment:=False
wdApp.Selection.InsertFile FileName:="5.doc", Range:="", ConfirmConversions:= _
False, Link:=False, Attachment:=False
wdApp.Selection.InsertFile FileName:="6.doc", Range:="", ConfirmConversions:= _
False, Link:=False, Attachment:=False
wdApp.Selection.InsertFile FileName:="7.doc", Range:="", ConfirmConversions:= _
False, Link:=False, Attachment:=False
wdApp.Selection.InsertFile FileName:="8.doc", Range:="", ConfirmConversions:= _
False, Link:=False, Attachment:=False
wdApp.Selection.InsertFile FileName:="9.doc", Range:="", ConfirmConversions:= _
False, Link:=False, Attachment:=False
wdApp.Selection.InsertFile FileName:="10.doc", Range:="", ConfirmConversions:= _
False, Link:=False, Attachment:=False
wdApp.Selection.InsertFile FileName:="11.doc", Range:="", ConfirmConversions:= _
False, Link:=False, Attachment:=False
wdApp.Selection.InsertFile FileName:="12.doc", Range:="", ConfirmConversions:= _
False, Link:=False, Attachment:=False
wdApp.Selection.InsertFile FileName:="13.doc", Range:="", ConfirmConversions:= _
False, Link:=False, Attachment:=False
wdApp.Selection.MoveUp Unit:=wdLine, Count:=191
wdDoc.TablesOfContents.Add Range:=Selection.Range, RightAlignPageNumbers:= _
True, UseHeadingStyles:=True, UpperHeadingLevel:=1, _
LowerHeadingLevel:=3, IncludePageNumbers:=True, AddedStyles:="", _
UseHyperlinks:=True, HidePageNumbersInWeb:=True, UseOutlineLevels:= _
True
wdDoc.TablesOfContents(1).TabLeader = wdTabLeaderDots
wdDoc.TablesOfContents.Format = wdIndexIndent
wdApp.ChangeFileOpenDirectory "C:\Users\Administrator\Desktop\"
wdApp.ActiveDocument.SaveAs FileName:="一1.doc", FileFormat:=wdFormatDocument, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False
wdApp.ActiveWindow.Close
VBA代码转换VB代码
'首先要将“工程-引用”中的Mic… Excel…选中
'Set xlBook = xlApp.Workbooks.Open("文件名") '打开已经存在的EXCEL工件簿文件
'xlApp.Visible = True '设置EXCEL对象可见(或不可见)
'Set xlSheet = xlBook.Worksheets("表名") '设置活动工作表
'Range("K12").Select 设置活动单元格
'xlSheet.Cells(Row, col) = 值 '给单元格(row,col)赋值
'xlSheet.PrintOut '打印工作表
'xlBook.Close (True) '关闭工作簿
'xlApp.Quit '结束EXCEL对象
'Set xlApp = Nothing '释放xlApp对象.
'xlBook.RunAutoMacros (xlAutoOpen) '运行EXCEL启动宏
'xlBook.RunAutoMacros (xlAutoClose) '运行EXCEL关闭宏
'xlBook.Worksheets.Count '工作簿标签总数
Private Sub Command1_Click()
Dim xlApp As Excel.Application
Set xlApp = New Excel.Application
Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象
On Error Resume Next
Workbooks.Add '新建工作簿
MkDir "C:\123"
ChDir "C:\123" '在桌面上建“123”文件夹
'以下是将文件保存到“C:\\模板.xls”
ActiveWorkbook.SaveAs FileName:= _
"C:\123\模板.xls", FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False
'Windows("模板.xls").Activate
xlApp.Visible = True
'Sheets("Sheet1").Select
Sheets.Add '新建工作表
Sheets("Sheet2").Name = "新建工作表"
'Sheets("Sheet3").Name = "Sheet"
ActiveWorkbook.Sheets("新建工作表").Tab.ColorIndex = 7 '给工作表标签指定颜色
xlApp.Worksheets("新建工作表").Range("A1").Cells(3, 2) = "添加数据"
'xlApp.Worksheets(Sheets(i).Name).Range("A1").Cells(j, 2) = "@"
'ActiveWorkbook.Sheets("考评").Tab.ColorIndex = 7
'ActiveWorkbook.Sheets("教师任课").Tab.ColorIndex = 7
'ActiveWorkbook.Sheets("班级设置").Tab.ColorIndex = 7
'ActiveWorkbook.Sheets("Zxmd").Tab.ColorIndex = 32
xlBook.Save
xlApp.Save
ActiveWorkbook.Close
xlBook.Close (True) '关闭工作簿
xlApp.Quit '结束EXCEL对象.
Set xlApp = Nothing '释放xlApp对象
End Sub
还可以到我博客中参阅其他有关代码
名称栏目:vba转换vb.net6 vba和vbnet
文章链接:http://hbruida.cn/article/docdchh.html