Can I use My.Computer.Network.DownloadFile in an access db? - vb.net

I'm trying to download a file from the internet by clicking a button in MS Access.
I'm trying to use My.Computer.Network.DownloadFile as described here:
http://msdn.microsoft.com/en-us/library/1say4ws7(v=vs.80).aspx
Private Sub Command2_Click()
My.Computer.Network.DownloadFile("http://www.example.com/temp/xml_test.xml", "C:\xml_test.xml")
End Sub
but the 'Microsoft Visual Basic for Applications' IDE that I'm typing this into seems to have no idea what I'm talking about (text just turns red).
Can I just not do this through the built in VB editor or can I simply load a library or something to make it work?
Sorry but I'm very new to VB and to Access so search results are not specific enough for me to understand - lord knows I've tried.
I'm using Access 2010 but the DB was created in an previous version - not sure if that matters.

You can't use any .NET libraries in Access/VBA.
I recommend you check out Pearson's code for downloading files, posted on his website. It says it's written for Excel but it should work in Access. http://www.cpearson.com/excel/DownloadFile.aspx
To contradict my first statement, technically there are actually a few .Net libraries that can be called from VBA if you know how to do it (late binding only, for one thing). I'm having trouble finding the information on that right now. And I somewhat doubt that the library you're trying to use here is one of them. If I remember correctly, some of the encryption library can be used in VBA.

Related

How can I expose Word VBA macro code as text files in VSC to better commit and track code changes?

Background and Problem
I lead a team of tech writers. Our team has a Word template (.dotm file) that has a bunch of VBA macros we've created over the years to help us automate tasks in Word. The macros are obviously stored inside of a .dotm template. Given that the code is stored in a binary file, the code is not easily traceable across commits.
Currently, we have to pull the changes on the branch and then open the macro inside Word's embedded code editor from the .dotm. But there's no way to see what exact code changes someone else made line by line or resolve conflicts using something like Beyond Compare.
What I Need
I'd like to find a way to automatically expose the VBA code from the .dotm as some kind of text file so that we can:
Do Word VBA coding tasks within VSC
Easily track and review each others code changes at the line level using our git repository
Resolve merge conflicts more easily
Has anyone found a way to do this?
What I've tried
I've tried searching online and on stackoverflow.
Hoping it might help, I installed ScriptLab, and I after following the MS tutorial, I now have Office Add-Ons working with VSC.
(https://code.visualstudio.com/docs/other/office),
(https://learn.microsoft.com/en-us/office/dev/add-ins/tutorials/word-tutorial) While the Office Add-Ons through VSC does provide an alternate (more modern) way of automating using Javascript, and the .js files are commit-able, it's not providing a way to expose the Word VBA, at least not that I could see.
Thank you in advance!
ScriptLab add-on is for playing with JavaScript code instantly, not designed as a macro infrastructure in Office.
Sounds like you need to switch your VBA macros to COM add-ins rails. There is no converters that can do this part of work for you automatically.
You may consider creating a VB.NET based add-in. In that case you will avoid language translating issues. You may find the Converting Code from VBA to Visual Basic .NET article helpful. It presents issues to consider when converting your Microsoft Office solutions from Visual Basic for Applications (VBA) to Visual Basic .NET. Provides a general overview of their differences, and then uses examples from Word and Excel to describe how you can use Visual Studio Tools for the Microsoft Office System to convert your code.

How to call VSTO-code from VBA

Given is the following scenario: A .net-class-library with business logic and Excel 2010 Add-In (VSTO) to make it available for users. All is working fine. Now, we need to call some of the logic from VBA. Just something like addLog("no issue") or getString("for ID").
(I know, standard solution is: creating a COM-visible dll and reference it within the VBA-project. However this wouldn't work in the current environment because of missing admin-credentials.)
Now, I am searching a way to make this happen. What I found is:
DDE - but everyone is screaming that it is really outdated
WCF-Service hosted within the VSTO Add-In - but I couldn't find any example that fits vaguely
So, do you have any suggestion?
Thanks a lot in advance

Sharing VBA modules across MS Office Applications

I have a substantial bank of VBA modules written in an Excel 2010 add-in. Some of these are specific to Excel, but many are more general. For example one takes a part number and re-formats it; another contains a Case Select function to find a file in a network drive.
I want to use the common functions in Word and Outlook. I could copy and paste from the Excel to Word add-ins, but this makes it difficult to keep my code up to date - when I make an edit in one application, I must remember to copy to all the others.
My question is, is there any means of writing common code in one place (e.g. in the Excel add-in, or some other common location) so that all MS Office applications can access it as it if it's just another module?
The way this used to be done was to take your code and compile it into a COM (or ActiveX) DLL using Visual Basic 6. Then you could add that DLL, using the VBA editor's "Tools...References" dialog, from any Office (or other) product that supported VBA, the same way you might use, say, the Microsoft Scripting Runtime, which is super-handy for things like Dictionary, FileSystemObject and TextStream.
Problem is, VB6 was released sometime in 1998 and has not been available from or supported by Microsoft for years now. There seem to be quite a few download sites offering the package - I can't offer any advice about the legality or security issues that might be experienced by using them...
Shamefully, Microsoft dropped the VBA ball years ago - it seems they mostly wish it would just Go Away.
You would need to create a COM add-in (.dll) for that, which would require Visual Studio or some other tool capable of creating COM exposed addins. There hasn't been any facility for this in Office since the old Office Developer edition.
VB6 is best way. VB6 is still supported for compiled programs. The IDE been tested and found to work up to Windows 10 (32 bit only) by MS but is unsupported.
If you want to convert to vbscript you can use wsc files instead of a dll.
From Script Components Overview
Windows® Script Components are an exciting new technology that allows you to create powerful, reusable COM components with easy-to-use scripting languages such as Microsoft® Visual Basic® Scripting Edition (VBScript) and Microsoft® JScript®.
Make one, make a type library, set a reference to typelibrary in Word and Excel.
Maybe can help somebody.
My solution has been set conditional compiler arguments in project properties:
In excel project: SOFT_EXCEL = 1 : SOFT_OUTLOOK = 0
In outlook project: SOFT_EXCEL = 0 : SOFT_OUTLOOK = 1
Then, in module:
Public Sub as_email()
#If SOFT_EXCEL Then
Debug.Print "this executes and compiles in excel"
#End If
#If SOFT_OUTLOOK Then
Debug.Print "this executes and compiles in outlook"
#End If
End Sub

Confused with code conversion from VBA

My question might sound stupid but please bear with me :-)
I have an excel file, was doing some manual task, converted them to VBA code in order to automate. Works well.
I then decided why not distribute this. So, I went about searching for ways to protect the VBA code and found none. The most probable way was to convert it to DLL and call the DLL using "Tools-> add references->mytoolsDLL" inside excel. As the DLL code is not seen it does offer some protection. So, I looked up how to convert my VBA to DLL. Solution found "Visual Studio-> Class Library Project"! SO converted almost all VBA to DLL using Class Library Project, compiled, registered my DLL, used it inside Excel, all good, works well.
Now, this DLL I have compiled I dont know if it is classified as "COM add-in" or ".NET" DLL! Today I realised that it was very easy to "de-compile" a .NET DLL. I tried looking at "code" difference between a COM ADDIN and .NET there is almost none. When coding this "DLL", I was using google and MSDN a lot but they all referenced it as "VB"
If I am converting VBA to something, should it be "COM ADD-IN" or ".NET"? I read about VSTO today and was wondering how does VSTO come inbetween Visual Studio and COM ADDIN/.NET? What techniques can I use to ensure that the DLL when distributed can be license controlled? i.e. after first "install" the DLL cannot be copied to other machines? Is it possible to do license management/control via VSTO?
p.s: If you think I am mixing up terms/terminologies please feel free to correct me
Why not just right click your project once you are in the developer environment, select VBAProject Properties, select Protection Tab and set a password to protect your vba project ?

Using the Office Interop for Word and Outlook 2007 in VB.NET

I need interop in my programs to automate several functions in Word and Outlook. Does anyone know a good place to start. My goal is to kick off a mail merge, create several different files and save them accordingly, then e-mail the different files to different people based upon who needs what. Any help learning how to use the interop properly would be greatly appreciated.
I am currently using Visual Studio 2008 and Office 2007 and use vb.net to write my programs.
A good way to get started is to use the macro editor to record the steps you are trying to perform. You can take the generated macro code and modify it for your purposes to suit. Click on the names of functions and variables of which you do not know the purpose and hit "F1" to get context specific help.
Add COM references to Outlook 12.0 Object library and Word 12.0 Object library.
This web page really helped kick me off: http://support.microsoft.com/kb/316383
Then, by recording macros you'll expose a lot of the stuff you'll likely want to work with. Word of warning, however, is that not everything exposed in VBA (macros) is accessible within VB .NET. I don't know why this is, but I've actually had to construct and execute a macro from VB.NET, written in VBA, within Excel to accomplish something that seemed ridiculously easy if it weren't for the strange disconnect between the two.
Some good info on Mail Merge: http://support.microsoft.com/kb/258512
Here's an article with some basic steps to get you up and connected with Outlook's Interop: http://support.microsoft.com/kb/313787
Hope this helps. I'll keep an eye out for questions from you here--I'd say I know quite a bit when it comes to interop.
You might want to start here: http://msdn.microsoft.com/en-us/office/bb266408.aspx.
There are a number of tutorials.