PC Review


Reply
Thread Tools Rate Thread

Converting From VB.Net or C# to VBA

 
 
Neil
Guest
Posts: n/a
 
      24th Aug 2012
I have some code I need to convert from VB.net to VB or VBA (I will be
using it in Access 2010). The code is to upload a document to a
SharePoint library (using the SharePoint Foundation 2010 Managed COM).
The original code was in C#. I used a C# to VB.Net converter to get it
into VB.Net. Now I need to get it into VB or VBA. Is it possible?

Here is the original C# code (from
http://msdn.microsoft.com/en-us/library/ee956524.aspx):

using System;
using System.IO;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using Microsoft.SharePoint.Client;
// The following directive avoids ambiguity between the
// System.IO.File class and Microsoft.SharePoint.Client.File class.
using ClientOM = Microsoft.SharePoint.Client;
class Program
{
static void Main(string[] args)
{
ClientContext clientContext =
new ClientContext("http://intranet.contoso.com");
using (FileStream fileStream =
new FileStream("NewDocument.docx", FileMode.Open))
ClientOM.File.SaveBinaryDirect(clientContext,
"/Shared Documents/NewDocument.docx", fileStream, true);
}
}

And here is the code after it was converted to VB.Net:

Imports System.IO
Imports DocumentFormat.OpenXml.Packaging
Imports DocumentFormat.OpenXml.Wordprocessing
Imports Microsoft.SharePoint.Client
' The following directive avoids ambiguity between the
' System.IO.File class and Microsoft.SharePoint.Client.File class.
Imports ClientOM = Microsoft.SharePoint.Client
Class Program
Private Shared Sub Main(args As String())
Dim clientContext As New ClientContext("http://intranet.contoso.com")
Using fileStream As New FileStream("NewDocument.docx", FileMode.Open)
ClientOM.File.SaveBinaryDirect(clientContext, "/Shared
Documents/NewDocument.docx", fileStream, True)
End Using
End Sub
End Class

Any idea how this would look in VB or VBA?

Thanks!

Neil
 
Reply With Quote
 
 
 
 
The Mad Ape
Guest
Posts: n/a
 
      24th Aug 2012


Neil wrote:
> I have some code I need to convert from VB.net to VB or VBA (I will be
> using it in Access 2010). The code is to upload a document to a
> SharePoint library (using the SharePoint Foundation 2010 Managed COM).
> The original code was in C#. I used a C# to VB.Net converter to get it
> into VB.Net. Now I need to get it into VB or VBA. Is it possible?
>
> Here is the original C# code (from
> http://msdn.microsoft.com/en-us/library/ee956524.aspx):
>
> using System;
> using System.IO;
> using DocumentFormat.OpenXml.Packaging;
> using DocumentFormat.OpenXml.Wordprocessing;
> using Microsoft.SharePoint.Client;
> // The following directive avoids ambiguity between the
> // System.IO.File class and Microsoft.SharePoint.Client.File class.
> using ClientOM = Microsoft.SharePoint.Client;
> class Program
> {
> static void Main(string[] args)
> {
> ClientContext clientContext =
> new ClientContext("http://intranet.contoso.com");
> using (FileStream fileStream =
> new FileStream("NewDocument.docx", FileMode.Open))
> ClientOM.File.SaveBinaryDirect(clientContext,
> "/Shared Documents/NewDocument.docx", fileStream, true);
> }
> }
>
> And here is the code after it was converted to VB.Net:
>
> Imports System.IO
> Imports DocumentFormat.OpenXml.Packaging
> Imports DocumentFormat.OpenXml.Wordprocessing
> Imports Microsoft.SharePoint.Client
> ' The following directive avoids ambiguity between the
> ' System.IO.File class and Microsoft.SharePoint.Client.File class.
> Imports ClientOM = Microsoft.SharePoint.Client
> Class Program
> Private Shared Sub Main(args As String())
> Dim clientContext As New ClientContext("http://intranet.contoso.com")
> Using fileStream As New FileStream("NewDocument.docx", FileMode.Open)
> ClientOM.File.SaveBinaryDirect(clientContext, "/Shared
> Documents/NewDocument.docx", fileStream, True)
> End Using
> End Sub
> End Class
>
> Any idea how this would look in VB or VBA?
>
> Thanks!
>
> Neil


I have no idea but you may want to try http://experts-exchange.com. They
may figure it out but you pay for the service.
 
Reply With Quote
 
 
 
 
Arne Vajhøj
Guest
Posts: n/a
 
      25th Aug 2012
On 8/24/2012 12:28 PM, Neil wrote:
> I have some code I need to convert from VB.net to VB or VBA (I will be
> using it in Access 2010). The code is to upload a document to a
> SharePoint library (using the SharePoint Foundation 2010 Managed COM).
> The original code was in C#. I used a C# to VB.Net converter to get it
> into VB.Net. Now I need to get it into VB or VBA. Is it possible?
>
> Here is the original C# code (from
> http://msdn.microsoft.com/en-us/library/ee956524.aspx):
>
> using System;
> using System.IO;
> using DocumentFormat.OpenXml.Packaging;
> using DocumentFormat.OpenXml.Wordprocessing;
> using Microsoft.SharePoint.Client;
> // The following directive avoids ambiguity between the
> // System.IO.File class and Microsoft.SharePoint.Client.File class.
> using ClientOM = Microsoft.SharePoint.Client;
> class Program
> {
> static void Main(string[] args)
> {
> ClientContext clientContext =
> new ClientContext("http://intranet.contoso.com");
> using (FileStream fileStream =
> new FileStream("NewDocument.docx", FileMode.Open))
> ClientOM.File.SaveBinaryDirect(clientContext,
> "/Shared Documents/NewDocument.docx", fileStream, true);
> }
> }
>
> And here is the code after it was converted to VB.Net:
>
> Imports System.IO
> Imports DocumentFormat.OpenXml.Packaging
> Imports DocumentFormat.OpenXml.Wordprocessing
> Imports Microsoft.SharePoint.Client
> ' The following directive avoids ambiguity between the
> ' System.IO.File class and Microsoft.SharePoint.Client.File class.
> Imports ClientOM = Microsoft.SharePoint.Client
> Class Program
> Private Shared Sub Main(args As String())
> Dim clientContext As New
> ClientContext("http://intranet.contoso.com")
> Using fileStream As New FileStream("NewDocument.docx",
> FileMode.Open)
> ClientOM.File.SaveBinaryDirect(clientContext, "/Shared
> Documents/NewDocument.docx", fileStream, True)
> End Using
> End Sub
> End Class
>
> Any idea how this would look in VB or VBA?


It could be difficult translating those .NET library
calls into equivalent COM calls.

I say that the easiest way forward us to rewrite the C# console
app above to expose a COM interface and then call that from VBA.

Arne


 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      25th Aug 2012
On 8/24/2012 2:25 PM, The Mad Ape wrote:
> Neil wrote:
>> I have some code I need to convert from VB.net to VB or VBA (I will be
>> using it in Access 2010). The code is to upload a document to a
>> SharePoint library (using the SharePoint Foundation 2010 Managed COM).
>> The original code was in C#. I used a C# to VB.Net converter to get it
>> into VB.Net. Now I need to get it into VB or VBA. Is it possible?


> I have no idea but you may want to try http://experts-exchange.com. They
> may figure it out but you pay for the service.


E-E is what was used 5-10 years ago. Today it is SO.

But I find it a bit distasteful to suggest other
fora than usenet given that there are usenet groups
where this question could be answered.

Arne

 
Reply With Quote
 
The Mad Ape
Guest
Posts: n/a
 
      25th Aug 2012


Arne Vajhøj wrote:
> On 8/24/2012 2:25 PM, The Mad Ape wrote:
>> Neil wrote:
>>> I have some code I need to convert from VB.net to VB or VBA (I will be
>>> using it in Access 2010). The code is to upload a document to a
>>> SharePoint library (using the SharePoint Foundation 2010 Managed COM).
>>> The original code was in C#. I used a C# to VB.Net converter to get it
>>> into VB.Net. Now I need to get it into VB or VBA. Is it possible?

>
>> I have no idea but you may want to try http://experts-exchange.com. They
>> may figure it out but you pay for the service.

>
> E-E is what was used 5-10 years ago. Today it is SO.
>
> But I find it a bit distasteful to suggest other
> fora than usenet given that there are usenet groups
> where this question could be answered.
>
> Arne
>


I don't see too many helping him out. Do you? If you find it distasteful
you whiny bitch then help him out or **** off.

TMA
 
Reply With Quote
 
Neil
Guest
Posts: n/a
 
      25th Aug 2012
Thanks, everyone, for your replies! I actually found another way to
accomplish this that didn't use the SP Foundation COM. So, was able to
write it directly in VBA. Thanks for the input, though. Appreciate it!

Neil


On 8/24/2012 11:28 AM, Neil wrote:
> I have some code I need to convert from VB.net to VB or VBA (I will be
> using it in Access 2010). The code is to upload a document to a
> SharePoint library (using the SharePoint Foundation 2010 Managed COM).
> The original code was in C#. I used a C# to VB.Net converter to get it
> into VB.Net. Now I need to get it into VB or VBA. Is it possible?
>
> Here is the original C# code (from
> http://msdn.microsoft.com/en-us/library/ee956524.aspx):
>
> using System;
> using System.IO;
> using DocumentFormat.OpenXml.Packaging;
> using DocumentFormat.OpenXml.Wordprocessing;
> using Microsoft.SharePoint.Client;
> // The following directive avoids ambiguity between the
> // System.IO.File class and Microsoft.SharePoint.Client.File class.
> using ClientOM = Microsoft.SharePoint.Client;
> class Program
> {
> static void Main(string[] args)
> {
> ClientContext clientContext =
> new ClientContext("http://intranet.contoso.com");
> using (FileStream fileStream =
> new FileStream("NewDocument.docx", FileMode.Open))
> ClientOM.File.SaveBinaryDirect(clientContext,
> "/Shared Documents/NewDocument.docx", fileStream, true);
> }
> }
>
> And here is the code after it was converted to VB.Net:
>
> Imports System.IO
> Imports DocumentFormat.OpenXml.Packaging
> Imports DocumentFormat.OpenXml.Wordprocessing
> Imports Microsoft.SharePoint.Client
> ' The following directive avoids ambiguity between the
> ' System.IO.File class and Microsoft.SharePoint.Client.File class.
> Imports ClientOM = Microsoft.SharePoint.Client
> Class Program
> Private Shared Sub Main(args As String())
> Dim clientContext As New
> ClientContext("http://intranet.contoso.com")
> Using fileStream As New FileStream("NewDocument.docx",
> FileMode.Open)
> ClientOM.File.SaveBinaryDirect(clientContext, "/Shared
> Documents/NewDocument.docx", fileStream, True)
> End Using
> End Sub
> End Class
>
> Any idea how this would look in VB or VBA?
>
> Thanks!
>
> Neil


 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      25th Aug 2012
On 8/25/2012 5:51 AM, The Mad Ape wrote:
> Arne Vajhøj wrote:
>> On 8/24/2012 2:25 PM, The Mad Ape wrote:
>>> Neil wrote:
>>>> I have some code I need to convert from VB.net to VB or VBA (I will be
>>>> using it in Access 2010). The code is to upload a document to a
>>>> SharePoint library (using the SharePoint Foundation 2010 Managed COM).
>>>> The original code was in C#. I used a C# to VB.Net converter to get it
>>>> into VB.Net. Now I need to get it into VB or VBA. Is it possible?

>>
>>> I have no idea but you may want to try http://experts-exchange.com. They
>>> may figure it out but you pay for the service.

>>
>> E-E is what was used 5-10 years ago. Today it is SO.
>>
>> But I find it a bit distasteful to suggest other
>> fora than usenet given that there are usenet groups
>> where this question could be answered.

>
> I don't see too many helping him out. Do you?


Yes.

He got two replies with two different approaches.

> If you find it distasteful
> you whiny bitch then help him out or **** off.


I did.

You did not.

So ...

Arne


 
Reply With Quote
 
Martin Crouch
Guest
Posts: n/a
 
      29th Aug 2012
On 24/08/2012 17:28, Neil wrote:
> I have some code I need to convert from VB.net to VB or VBA (I will be
> using it in Access 2010). The code is to upload a document to a
> SharePoint library (using the SharePoint Foundation 2010 Managed COM).
> The original code was in C#. I used a C# to VB.Net converter to get it


>
> Any idea how this would look in VB or VBA?
>
> Thanks!
>
> Neil


You could do it by building a COM interop library to wrap the .NET
sharepoint stuff as COM.

Here's an example:
http://richnewman.wordpress.com/2007...ry-from-excel/

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting a date to a text field w/o converting it to a julian da LynnMinn Microsoft Excel Worksheet Functions 2 6th Mar 2008 04:43 PM
Converting Time to decimals and then converting decimals to time neil_val@tiscali.co.uk Microsoft Excel Worksheet Functions 1 30th Nov 2007 05:09 PM
Access VBA - declared an Excel VBA reserved word and VBA/Access won't give it back! ultar6@gmail.com Microsoft Access 1 16th Jun 2007 05:11 AM
Converting Excel 97 VBA to Excel 2002 VBA? Anny. Microsoft Excel Programming 1 11th Jun 2004 12:46 AM
Converting VBA app to VB.net project Patrick Molloy Microsoft Excel Programming 2 19th Aug 2003 12:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:03 AM.