Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using .Net to get data for Word 2007 VBA macro

3 views
Skip to first unread message

edamron

unread,
Apr 28, 2009, 4:32:34 PM4/28/09
to
My shop is converting all of our Word 2002 macros to Word 2007.

Our current macros retrieve data from a Microsoft SQL database. To do
this I created an activeX object that was between our database and the
data enabled templates.

I know that .Net has great database support but once I execute a
stored procedure and have the data in a object created with managed
code, is there any way for our templates to access the data without
themselves being rewritten in .Net? I.E. We want to access the data
via macros written in VBA.

Thanks.

Cindy M.

unread,
Apr 29, 2009, 5:33:54 AM4/29/09
to
Hi Edamron,

I'm not really sure how you're envisioning this, but taken literally:

No, there's no way your VBA can use a .NET dataset. You'd need to
convert that data to something Office can work with. This could be an
array, a delimited string or a XML (as a string) if you don't want to
write the data to a file and have the VBA pick up the file.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :-)

Luft

unread,
Apr 29, 2009, 1:32:23 PM4/29/09
to
On Apr 29, 2:33 am, Cindy M. <C.Meiste...@hispeed.ch> wrote:
> Hi Edamron,
>
> I'm not really sure how you're envisioning this, but taken literally:
>
> No, there's no way your VBA can use a .NET dataset. You'd need to
> convert that data to something Office can work with. This could be an
> array, a delimited string or a XML (as a string) if you don't want to
> write the data to a file and have the VBA pick up the file.
>
> > My shop is converting all of our Word 2002 macros to Word 2007.
>
> > Our current macros retrieve data from a Microsoft SQL database.  To do
> > this I created an activeX object that was between our database and the
> > data enabled templates.
>
> > I know that .Net has great database support but once I execute a
> > stored procedure and have the data in a object created with managed
> > code, is there any way for our templates to access the data without
> > themselves being rewritten in .Net?  I.E. We want to access the data
> > via macros written in VBA.
>
> Cindy Meister
> INTER-Solutions, Switzerlandhttp://homepage.swissonline.ch/cindymeister(last update Jun 17 2005)http://www.word.mvps.org

>
> This reply is posted in the Newsgroup; please post any follow question
> or reply in the newsgroup and not by e-mail :-)

Thanks Cindy.

I would rather not write a file and pick it up from VBA if I can avoid
it. If my VB.NET code puts the data into a string how do I make that
string accessible from VBA? Can I pass an array from VB.Net code to
VBA code? Can you show me a code snippit that does this?

Thanks again.

Cindy M.

unread,
Apr 30, 2009, 6:11:57 AM4/30/09
to
Hi Luft,

> I would rather not write a file and pick it up from VBA if I can avoid
> it. If my VB.NET code puts the data into a string how do I make that
> string accessible from VBA? Can I pass an array from VB.Net code to
> VBA code? Can you show me a code snippit that does this?
>

I don't have time just now to work out an example that meets your exact
scenario. But see if this article in the MSDN documentation gets you
started?

http://msdn.microsoft.com/en-us/library/bb608621.aspx

It should show you how to create a function in your VSTO app that can be
called by VBA and return a value (a string, for example).

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)

Luft

unread,
Apr 30, 2009, 11:21:49 AM4/30/09
to
On Apr 30, 3:11 am, Cindy M. <C.Meiste...@hispeed.ch> wrote:
> Hi Luft,
>
> > I would rather not write a file and pick it up from VBA if I can avoid
> > it.  If my VB.NET code puts the data into a string how do I make that
> > string accessible from VBA?  Can I pass an array from VB.Net code to
> > VBA code?  Can you show me a code snippit that does this?
>
> I don't have time just now to work out an example that meets your exact
> scenario. But see if this article in the MSDN documentation gets you
> started?
>
> http://msdn.microsoft.com/en-us/library/bb608621.aspx
>
> It should show you how to create a function in your VSTO app that can be
> called by VBA and return a value (a string, for example).
>
> Cindy Meister
> INTER-Solutions, Switzerlandhttp://homepage.swissonline.ch/cindymeister(last update Jun 17 2005)http://www.word.mvps.org

>
> This reply is posted in the Newsgroup; please post any follow question
> or reply in the newsgroup and not by e-mail :-)

Thanks Cindy. That's perfect.

0 new messages