简体   繁体   English

VB与VBA有什么区别?

[英]what is the difference between VB vs VBA?

I am working on this project (an AddIn) for Excel 2007. It use aspose cells for this purpose as well as C#. 我正在为Excel 2007开发这个项目(一个AddIn)。它为此目的使用aspose单元以及C#。 I didn't write the code, but took over the project from somebody else. 我没有编写代码,但是接管了其他人的项目。 So I am still learning the excel portion as I know only C#. 所以我仍在学习excel部分,因为我只知道C#。 I did notice there is some code for creating workbook/worksheet. 我注意到有一些代码用于创建工作簿/工作表。 How do I know if its written in VB or VBA so that i can learn it?The file extensions are like .cls, .frm, .bas etc. I am using Visual Studio 2010. 我如何知道它是用VB还是VBA编写的,以便我可以学习它?文件扩展名就像.cls,.frm,.bas等。我使用的是Visual Studio 2010。

Also the workbook/worksheets are password protected after creation.When I tried to change the password through VB/VBA code(whatever it is), it creates errors during build such as identifier expected, declaration expected etc.But when I undid the changes, all the errors disappeared. 此外,工作簿/工作表在创建后也受密码保护。当我尝试通过VB / VBA代码(无论是什么)更改密码时,它会在构建期间产生错误,例如标识符预期,声明预期等。但是当我取消更改时,所有的错误都消失了。 The only change I made was change the string that stored the password. 我做的唯一更改是更改存储密码的字符串。 (string "password" was changed to "password1") and suddenly other lines of code started getting errors.The errors are identifier expected, declaration expected etc. and that doesn't make sense to me. (字符串“password”已更改为“password1”)并突然其他代码行开始出错。错误是预期的标识符,声明预期等等,这对我没有意义。 So i had to change the password through C# after it was password protected through VB/VBA. 因此,在通过VB / VBA进行密码保护后,我必须通过C#更改密码。 Also, how do I debug VB/VBA code. 另外,我如何调试VB / VBA代码。 I tried putting breakpoints through VS2010 , but it's not hitting them when I run the project.I am sure the worksheets are created using VB/VBA and so its getting inside those codes, but cant debug. 我尝试通过VS2010设置断点,但是当我运行项目时它没有击中它们。我确信工作表是使用VB / VBA创建的,所以它进入这些代码,但无法调试。

I open the AddIn using Visual Studio2010 and that's how work with the code,both C# and VB/VBA.I dont modify anything using Alt+F11. 我使用Visual Studio2010打开AddIn,这就是如何使用C#和VB / VBA代码。我不使用Alt + F11修改任何内容。

.cls, .frm, and .bas are VBA files. .cls,.frm和.bas是VBA文件。 I suggest you try debugging the code in Excel using the VBE (the Visual Studio equivillent for VBA). 我建议你尝试使用VBE(Visual Studio等效的VBA)在Excel中调试代码。 It's quite easy to debug in that enviornment. 在这个环境中进行调试非常容易。

The difference between VB (VB.Net) and VBA is quite big. VB(VB.Net)和VBA之间的区别非常大。 That being said, VBA is a rather simple language, so if you have managed to grasp C#, I'm sure you can learn VBA with a little bit of reading and experimentation. 话虽如此,VBA是一种相当简单的语言,所以如果你能够掌握C#,我相信你可以通过一些阅读和实验来学习VBA。

If you have a question about the actual code, I suggest you post it as a seperate question. 如果您对实际代码有疑问,我建议您将其作为单独的问题发布。 :) :)

How do you get to the code? 你怎么得到代码? If through Excel by using the VBE, for instance by pressing Alt+F11, then it is VBA. 如果通过Excel使用VBE,例如按Alt + F11,那么它是VBA。 If you open a project, then it is probably VB (VB6). 如果你打开一个项目,那么它可能是VB(VB6)。 Note that VB.NET use the .vb extension. 请注意,VB.NET使用.vb扩展名。 Moreover, since VBA is a subset of VB then if you export VBA from a VBE project, the exported files default to their VB cousin's file extensions. 此外,由于VBA是VB的子集,因此如果从VBE项目导出VBA,导出的文件默认为VB表兄弟的文件扩展名。

We really need to know how you get to the code. 我们真的需要知道你如何获得代码。

Like I said, VBA (6.x) is a subset of VB6. 就像我说的,VBA(6.x)是VB6的子集。 The Excel part is just an object model that uses VBA. Excel部分只是一个使用VBA的对象模型。 VB.NET is different and is not the case because the file extensions are wrong. VB.NET是不同的,因为文件扩展名是错误的。

Therefore, concentrate on learning on VBA and Excel 2007 Object Model 因此,请专注于学习VBA和Excel 2007对象模型

MSDN Search for VBA at http://social.msdn.microsoft.com/Search/en-US?query=VBA&ac=8 . MSDN在http://social.msdn.microsoft.com/Search/en-US?query=VBA&ac=8上搜索VBA。

Creating VBA Macros to Manipulate Worksheets in Excel 2007 at http://msdn.microsoft.com/en-us/library/dd553655(v=office.12).aspx . 创建VBA宏以在Excel 2007操作工作表网址http://msdn.microsoft.com/en-us/library/dd553655(v=office.12).aspx

This article VBA Interoperability with Visual Studio Tools for the Office System (3.0) at http://msdn.microsoft.com/en-us/library/bb931201(v=office.12).aspx should help. 本文的VBA与Office系统的Visual Studio工具的互操作性(3.0)http://msdn.microsoft.com/en-us/library/bb931201(v=office.12).aspx应该有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM