Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-01-2012, 07:17 AM
tinfanide tinfanide is offline C# / vb.net & vba? Windows 7 64bit C# / vb.net & vba? Office 2010 32bit
Expert
C# / vb.net & vba?
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default C# / vb.net & vba?

I started learning coding in the Office environment with VBA. I know it stands for Visual Basic for Application. As long as getting along with Windows, I started learning some VB.NET but always wonder why in every MSDN VBA reference page, there must be VB, C#, F#... code demostration.



Is VBA VB? I found they have some style differences:
Code:
' VBA
Dim var As Object
Set var = obj

'VB.NET
Dim var As Object = obj
' No "set" (to the best of my knowledge) in VB
And can I use C# in VBE, the VBA editor?
Or can I control Office Applications in C# in Visual Studio or just simply on Notepad and compile the codes in DOS?
Reply With Quote
  #2  
Old 02-03-2012, 03:56 PM
macropod's Avatar
macropod macropod is offline C# / vb.net & vba? Windows 7 64bit C# / vb.net & vba? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,340
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi tinfanide,

The various versions of VBA can be likened to dialects of VB6. Because VBA is application-specific, Word, Excel, Access, etc will each have will have methods, etc that aren't found in the others. VB6 won't have any of these application-specific extensions.

The MSDN pages will provide examples in various languages, because MS supports them (eg via Visual Studio), not because they're interchangeable.

Whilst you could add C# code to a VBA module, VBA wouldn't know what to do with it; you'd have to pass the C# code as a string or a series of strings to a C# compiler. And that entails automating the C# compiler.

Code written in C#, VB6, VB.NET, etc, can be used to control Office Applications by hooking into the application's VBA.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 02-03-2012, 08:33 PM
tinfanide tinfanide is offline C# / vb.net & vba? Windows 7 64bit C# / vb.net & vba? Office 2010 32bit
Expert
C# / vb.net & vba?
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
The MSDN pages will provide examples in various languages, because MS supports them (eg via Visual Studio), not because they're interchangeable.
How about writing the codes (VB.NET / C#) in Visual Studio? Can VS control Office Application?

Quote:
Code written in C#, VB6, VB.NET, etc, can be used to control Office Applications by hooking into the application's VBA.
How about VB.NET? Does it need to pass the codes to strings and compile them?
Reply With Quote
  #4  
Old 02-04-2012, 02:12 AM
macropod's Avatar
macropod macropod is offline C# / vb.net & vba? Windows 7 64bit C# / vb.net & vba? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,340
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by tinfanide View Post
How about writing the codes (VB.NET / C#) in Visual Studio? Can VS control Office Application?
VS is a suite of programming environments, any of which can control Office. That's the whole point of the code snippets for the different programming languages that you see in MSDN.
Quote:
How about VB.NET? Does it need to pass the codes to strings and compile them?
If you mean "can I use C# in VB.NET?". That's no different to trying to use C# in VBA. As for controlling Office, see above reply.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Other Forums: Access Forums

All times are GMT -7. The time now is 01:32 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft