Outlook Automation from VB.net (Visual Studio 201) - vb.net

We have some very old VB6 applications that used automation to create Excel Spreadsheets, Word Documents and Outlook Calendar events. Now we want to upgrade those applications to VB.net and perform the same automation tasks. Our issue is that there appears to be very sparse documentation on how to do this now. There is plenty on creating Add-Ons, or interacting with COM objects, but neither of these suit our purposes. We need to be able to interact with Office 2016 (which is presumably .Net not COM) directly to create our outputs. Any help greatly appreciated.

The Office object model is the same for all kind of applications - COM add-ins or automation applications. Anyway, you may find the following articles helpful:
How to automate Word from Visual Basic .NET to create a new document
How to automate Excel from Visual Basic .NET to fill or to obtain data in a range by using arrays
How to automate Microsoft Excel from Visual Basic .NET
How to automate Outlook by using Visual Basic

Related

Visual Studio vs VBA in Word

Is it benificial to download Visual Studio Community for VBA programming?
Or is it better just to run Visual Basics out of a word document
VBA and VB aren't the same thing.
VBA is Visual Basic for Applications and is derived from VB. VBA is encapsulated within Microsoft Office and is primarily event driven, whereas Visual Basic is a fully fledged OOP language that's used within the Visual Studio IDE.
You can create VSTO add-ins for office using VB within Visual Studio - but unless you have a specific reason to I would stick with using VBA as the language has been developed with Office automation in mind, and so the objects and the built in IDE providing features such as IntelliSense are already configured to help you achieve what you need
Ultimate point here is that there's no point re-inventing the wheel. Stick with VBA.

Copy VB.NET code from Visual Studio Express to Microsoft Access 2013

Is it possible to develop forms in Visual Studio Express, and copy the VB.NET code to Microsoft Access 2013? Because I'm not familiar with Visual Basic code in Microsoft Access.
No, it is not possible. Microsoft Access uses VBA (Visual Basic for Application) and VBA is a different Language than VB.NET.
Sure, you could write your DLL in a NET Language of your choice and call that DLL from Microsoft Access VBA code, but it is not an easy task.
Here there is a project that explain how to build a COM visible NET library that is callable from a VBA code. It is in C# but the principles are the same, just search for different syntax if really want to do it
I Thing if you know vb.net you should be able to learn "VBA" in no time is almost the same

VBA Compatibility between different Office Versions

Sorry if this is a silly question.
What can I do to make my VBA code work on Office 2003/2007/2010 ?
Can it be done or should I create different VBA code for each?
I use
WinHttp.WinHttpRequest.5.1
Make a lot of Windows API Calls
Have five references to libraries
wininet.dll
kernel32
Outlook.Application
InternetExplorer.Application
I'm developing on Office 2007 but users with Office 2010 cant run the code. Not sure about users runnning other office versions.
I have also seen that one can create an Excel-Addin in Visual Studio but I dont have a lot of experience in that area.
Thx for any suggestions.
for different versions of Excel, you can just use Conditional Compilation such as #If Application.version>n then
However, for any users who have Win64 systems, you will have to provide different methods of calling the API functions.
Your best bet is to try and manipulate Excel using Automation either from .NET using Office.Interop, or VSTO.

Excel vba project in VB.NET

I am now engaging in an excel vba project. It's a excel front interface for the workers in a site with an Access database in the company network. I dont like much the VBE in Excel 2007, so im wandering if I can do this with VB.NET, which seems to be a more adorable IDE. And where can I find some resources on this? Or recommanded books? Thanks!
Im using Excel 2007 et VB.NET 2008
You could also try Excel-DNA (free). There are many other products out there too. You can make it work with VB.Net Express also, you just need to add a reference to your excel SDK. Also, Add-in Express looks pretty nice. I've never tried it though (costs money).
I think you are looking for Visual Studio Tools for Office: VSTO.
This allows you to develop using VB.NET (or indeed C#) but with full access to the Office automation facilities.

Difference between Visual Basic 6.0 and VBA

What is the difference between the two. I always thought VBA is somewhat 'crippled' version of VB, but when a friend asked me the other day I had no idea what the actual differences are.
Also, when you use, for example, Excel, is that VB or VBA ?
For nearly all programming purposes, VBA and VB 6.0 are the same thing.
VBA cannot compile your program into an executable binary. You'll always need the host (a Word file and MS Word, for example) to contain and execute your project. You'll also not be able to create COM DLLs with VBA.
Apart from that, there is a difference in the IDE - the VB 6.0 IDE is more powerful in comparison. On the other hand, you have tight integration of the host application in VBA. Application-global objects (like "ActiveDocument") and events are available without declaration, so application-specific programming is straight-forward.
Still, nothing keeps you from firing up Word, loading the VBA IDE and solving a problem that has no relation to Word whatsoever. I'm not sure if there is anything that VB 6.0 can do (technically), and VBA cannot. I'm looking for a comparison sheet on the MSDN though.
VBA stands for Visual Basic for Applications and so is the small "for applications" scripting brother of VB.
VBA is indeed available in Excel, but also in the other office applications.
With VB, one can create a stand-alone windows application, which is not possible with VBA.
It is possible for developers however to "embed" VBA in their own applications, as a scripting language to automate those applications.
Edit: From the VBA FAQ:
Q. What is Visual Basic for Applications?
A. Microsoft Visual Basic for Applications (VBA) is an embeddable programming environment designed to enable developers to build custom solutions using the full power of Microsoft Visual Basic. Developers using applications that host VBA can automate and extend the application functionality, shortening the development cycle of custom business solutions.
Note that VB.NET is even another language, which only shares syntax with VB.
Here's a more technical and thorough answer to an old question: Visual Basic for Applications (VBA) and Visual Basic (pre-.NET) are not just similar languages, they are the same language. Specifically:
They have the same specification: The implementation-independent description of what the language contains and what it means. You can read it here: [MS-VBAL]: VBA Language Specification
They have the same platform: They both compile to Microsoft P-Code, which is in turn executed by the exact same virtual machine, which is implemented in the dll msvbvm[x.0].dll.
In an old VB reference book I came across last year, the author (Paul Lomax) even asserted that 'VBA' has always been the name of the language itself, whether used in stand-alone applications or in embedded contexts (such as MS Office):
"Before we go any further, let's just clarify on fundamental point. Visual Basic for Applications (VBA) is the language used to program in Visual Basic (VB). VB itself is a development environment; the language element of that environment is VBA."
The minor differences
Hosted vs. stand-alone: In practical, terms, when most people say "VBA" they specifically mean "VBA when used in MS Office", and they say "VB6" to mean "VBA used in the last version of the standalone VBA compiler (i.e. Visual Studio 6)". The IDE and compiler bundled with MS Office is almost identical to Visual Studio 6, with the limitation that it does not allow compilation to stand-alone dll or exe files. This in turns means that classes defined in embedded VBA projects are not accessible from non-embedded COM consumers, because they cannot be registered.
Continued development: Microsoft stopped producing a stand-alone VBA compiler with Visual Studio 6, as they switched to the .NET runtime as the platform of choice. However, the MS Office team continues to maintain VBA, and even released a new version (VBA7) with a new VM (now just called VBA7.dll) starting with MS Office 2010. The only major difference is that VBA7 has both a 32- and 64-bit version and has a few enhancements to handle the differences between the two, specifically with regards to external API invocations.
Do you want compare VBA with VB-Classic (VB6..) or VB.NET?
VBA (Visual Basic for Applications) is a vb-classic-based script language embedded in Microsoft Office applications. I think it's language features are similar to those of VB5 (it just lacks some few builtin functions), but:
You have access to the office document you wrote the VBA-script for and so you can e.g.
Write macros (=automated routines for little recurring tasks in your office-work)
Define new functions for excel-cell-formula
Process office data
Example: Set the value of an excel-cell
ActiveSheet.Cells("A1").Value = "Foo"
VBC and -.NET are no script languages. You use them to write standalone-applications with separate IDE's which you can't do with VBA (VBA-scripts just "exist" in Office)
VBA has nothing to do with VB.NET (they just have a similar syntax).
Actually VBA can be used to compile DLLs.
The Office 2000 and Office XP Developer editions included a VBA editor that could be used for making DLLs for use as COM Addins.
This functionality was removed in later versions (2003 and 2007) with the advent of the VSTO (VS Tools for Office) software, although obviously you could still create COM addins in a similar fashion without the use of VSTO (or VS.Net) by using VB6 IDE.
It's VBA. VBA means Visual Basic for Applications, and it is used for macros on Office documents. It doesn't have access to VB.NET features, so it's more like a modified version of VB6, with add-ons to be able to work on the document (like Worksheet in VBA for Excel).
VB is not a language. VB is a program that hosts VBA, just as Office hosts VBA. VB is a set of App objects, just like Word and Excel have, and a forms package, just like in Office.
So you can only write VBA code in VB.
PS this info is on the INFO tab on the VB question page for VB.
From VBA Info
VBA 6, was shipped in 1998 and includes a myriad of licensed hosts, among them: Office 2000 - 2010, AutoCAD, PI Processbook, and the stand-alone Visual Basic 6.0
VBA stands for Visual Basic For Applications and its a Visual Basic implementation intended to be used in the Office Suite.
The difference between them is that VBA is embedded inside Office documents (its an Office feature). VB is the ide/language for developing applications.
VB (Visual Basic only up to 6.0) is a superset of VBA (Visual Basic for Applications). I know that others have sort of eluded to this but my understanding is that the semantics (i.e. the vocabulary) of VBA is included in VB6 (except for objects specific to Office products), therefore, VBA is a subset of VB6. The syntax (i.e. the order in which the words are written) is exactly the same in VBA as it would be in VB6, but the difference is the objects available to VBA or VB6 are different because they have different purposes. Specifically VBA's purpose is to programatically automate tasks that can be done in MS Office, whereas VB6's purpose is to create standard EXE, ActiveX Controls, ActiveX DLLs and ActiveX EXEs which can either work stand alone or in other programs such as MS Office or Windows.