vba代码能不能直接在VB中运行?

 我来答
__________321
2012-06-24 · TA获得超过1087个赞
知道小有建树答主
回答量:549
采纳率:0%
帮助的人:547万
展开全部
大部分vba是不能直接在vb中运行的
最主要的区别是:vb是用来创建应用程序的,vba是寄生于现有的程序中(excel等)
vba过程中一般会直接调用到例如excel的单元格、行、列、sheet等对象元素,
直接搬到vb中运行,
1、需要加载引用项目:Microsoft Excel 11.0 object library
2、需要重新申明各个工作薄、工作表,才可以调用其中对象元素:
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
逻辑判断语法想通,几乎不用改
总之,若是设计工作表内部对象,需要修改地方很多,不能直接运行
wyw0113
2015-11-05 · TA获得超过2107个赞
知道大有可为答主
回答量:2519
采纳率:66%
帮助的人:975万
展开全部
可以在VB中运行。
Visual Basic for Applications(VBA)是Visual Basic的一种宏语言,是微软开发出来在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。主要能用来扩展Windows的应用程式功能,特别是Microsoft Office软件。也可说是一种应用程式视觉化的Basic 脚本。Visual Basic For Application(VBA),实际上VBA是寄生于VB应用程序的版本。微软在1994年发行的Excel5.0版本中,即具备了VBA的宏功能。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
weiluohongd36dc1e
2012-06-25
知道答主
回答量:67
采纳率:0%
帮助的人:10.7万
展开全部
不涉及appication,workbook ,worksheet ,range ,row,collomn等EXCEL宿主特有对象的语句,可以在VB下运行.
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友4dfb0fa
2019-03-31
知道答主
回答量:3
采纳率:0%
帮助的人:2667
展开全部
像这种?
Private Sub fangda_ck_Click()
'放大窗口两层开始=======================================================
If Me.fangda_ck.Visible = False Then Exit Sub
If Me.fangda_ck.Visible = True And Me.suoxiao_ck.Visible = False Then
Me.suoxiao_ck.Visible = True
Me.Frame5.Visible = True
Me.fangda_ck.Top = Me.fangda_ck.Top + 172
Me.suoxiao_ck.Top = Me.suoxiao_ck.Top + 172
Me.CommandButton10.Top = Me.CommandButton10.Top + 172
Me.Height = Me.Height + 172
ElseIf Me.fangda_ck.Visible = True Then
Me.fangda_ck.Visible = False
Me.Frame7.Visible = True
Me.Frame8.Visible = True
Me.Frame9.Visible = True
Me.fangda_ck.Left = Me.fangda_ck.Left + 252
Me.suoxiao_ck.Left = Me.suoxiao_ck.Left + 330
Me.CommandButton10.Left = Me.CommandButton10.Left + 252
Me.Width = Me.Width + 248
End If
'放大窗口两层结束=======================================================
End Sub
Private Sub suoxiao_ck_Click()
'缩小窗口两层开始=======================================================
If Me.suoxiao_ck.Visible = False Then Exit Sub
If Me.suoxiao_ck.Visible = True And Me.fangda_ck.Visible = False Then
Me.fangda_ck.Visible = True
Me.Frame7.Visible = False
Me.Frame8.Visible = False
Me.Frame9.Visible = False
Me.fangda_ck.Left = Me.fangda_ck.Left - 252
Me.suoxiao_ck.Left = Me.suoxiao_ck.Left - 330
Me.CommandButton10.Left = Me.CommandButton10.Left - 252
Me.Width = Me.Width - 248
ElseIf Me.suoxiao_ck.Visible = True Then
Me.fangda_ck.Visible = True
Me.suoxiao_ck.Visible = False
Me.Frame5.Visible = False
Me.fangda_ck.Top = Me.fangda_ck.Top - 172
Me.suoxiao_ck.Top = Me.suoxiao_ck.Top - 172
Me.CommandButton10.Top = Me.CommandButton10.Top - 172
Me.Height = Me.Height - 172
End If
'缩小窗口两层开始=======================================================
End Sub
Private Sub UserForm_Activate()
'初始化事件开始=======================================================
Me.suoxiao_ck.Visible = False
Me.fangda_ck.Visible = True
Me.Frame5.Visible = False
Me.Frame7.Visible = False
Me.Frame8.Visible = False
Me.Frame9.Visible = False
Me.fangda_ck.Top = fangda_ck.Top - 172
Me.CommandButton10.Top = Me.CommandButton10.Top - 172
Me.suoxiao_ck.Top = Me.suoxiao_ck.Top - 172
Me.fangda_ck.Left = Me.fangda_ck.Left - 252
Me.CommandButton10.Left = Me.CommandButton10.Left - 252
Me.suoxiao_ck.Left = Me.suoxiao_ck.Left - 252
Me.Height = Me.Height - 172
Me.Width = Me.Width - 248
'Me.ComboBox1.RowSource = "类别!A2:A6"
'Me.ComboBox2.RowSource = "类别!B2:B4"
'Me.Cmb_Spic.Enabled = False
'初始化事件开始=======================================================
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式