PC Review


Reply
Thread Tools Rate Thread

Can I save a copy of Excel workbook in MSSQL database using VBA?

 
 
=?Utf-8?B?S2FybGE=?=
Guest
Posts: n/a
 
      14th Mar 2007
Our User group would like a button in an Excel workbook that saves a copy of
the workbook in MSSQL database. We have done something similiar in a Web app
using C#. The excel workbook is stored in MSSQL db as an image. That app has
access to the workbook as a saved file, not as an active workbook during that
process. Converts the file to byte then image.

I can't duplicate the process successfully in VBA code. The workbook object
doesn't seem to support the Savepicture or CopyAsPicture functions. In order
to use the byte conversion I need the Length of the file(workbook), another
property I am unable to use with the workbook object.

Any help would be appreciated. I am using VBA 6.3. Thanks.


 
Reply With Quote
 
 
 
 
NickHK
Guest
Posts: n/a
 
      15th Mar 2007
Karla,
You cannot convert a WB to an image, but you can Copy/Paste Special a range
as a picture.
However, on my systems, you are limited to relatively small ranges.
You would still have to get the picture out of Excel and into a suitable
graphics format, either in memory or on disk, before you can send the bytes
to the DB.

If you could do it in C++, something similar in VB/VBA will (probably)
exist. Depends how you did it ?

It would be easier to install a <printer> that can convert to a graphic.
Possibly:
http://www.print-driver.com/howto/co...le_to_jpeg.htm

NickHK

"Karla" <(E-Mail Removed)> wrote in message
news:0A1C18EF-6CDC-474E-A219-(E-Mail Removed)...
> Our User group would like a button in an Excel workbook that saves a copy

of
> the workbook in MSSQL database. We have done something similiar in a Web

app
> using C#. The excel workbook is stored in MSSQL db as an image. That app

has
> access to the workbook as a saved file, not as an active workbook during

that
> process. Converts the file to byte then image.
>
> I can't duplicate the process successfully in VBA code. The workbook

object
> doesn't seem to support the Savepicture or CopyAsPicture functions. In

order
> to use the byte conversion I need the Length of the file(workbook),

another
> property I am unable to use with the workbook object.
>
> Any help would be appreciated. I am using VBA 6.3. Thanks.
>
>



 
Reply With Quote
 
=?Utf-8?B?S2FybGE=?=
Guest
Posts: n/a
 
      15th Mar 2007
Nick,

Thank you for your input. The 3rd party tool to convert to a graphic is
probably not an option as we would have to purchase licenses for an
enterprise application.

I will continue to pursue a VBA solution.
In C# (webapp) the code was:

// Get a ref to a PostedFile object
HttpPostedFile postedFile = myFile.PostedFile;

//Get size of uploaded file
int nFileLen = postedFile.ContentLength;

string fileNameFullPath = postedFile.FileName;
string filename = Path.GetFileName(fileNameFullPath);
//Allocate an byte array to store the data from the file uploaded
byte[] myData = new byte[nFileLen];
// setup SQL access (connection info omitted)
addEmp.Parameters.Add("@excel_workbook", SqlDbType.Image,
myData.Length).Value = myData;


Karla


"NickHK" wrote:

> Karla,
> You cannot convert a WB to an image, but you can Copy/Paste Special a range
> as a picture.
> However, on my systems, you are limited to relatively small ranges.
> You would still have to get the picture out of Excel and into a suitable
> graphics format, either in memory or on disk, before you can send the bytes
> to the DB.
>
> If you could do it in C++, something similar in VB/VBA will (probably)
> exist. Depends how you did it ?
>
> It would be easier to install a <printer> that can convert to a graphic.
> Possibly:
> http://www.print-driver.com/howto/co...le_to_jpeg.htm
>
> NickHK
>
> "Karla" <(E-Mail Removed)> wrote in message
> news:0A1C18EF-6CDC-474E-A219-(E-Mail Removed)...
> > Our User group would like a button in an Excel workbook that saves a copy

> of
> > the workbook in MSSQL database. We have done something similiar in a Web

> app
> > using C#. The excel workbook is stored in MSSQL db as an image. That app

> has
> > access to the workbook as a saved file, not as an active workbook during

> that
> > process. Converts the file to byte then image.
> >
> > I can't duplicate the process successfully in VBA code. The workbook

> object
> > doesn't seem to support the Savepicture or CopyAsPicture functions. In

> order
> > to use the byte conversion I need the Length of the file(workbook),

> another
> > property I am unable to use with the workbook object.
> >
> > Any help would be appreciated. I am using VBA 6.3. Thanks.
> >
> >

>
>
>

 
Reply With Quote
 
NickHK
Guest
Posts: n/a
 
      16th Mar 2007
Karla,
If it is licensing issue on that component that you use already, then it is
irrelevant.
Install a virtual printer that output in the desired image format, or one
the many freely available PDF printers.

NickHK

"Karla" <(E-Mail Removed)> wrote in message
news:89FAD4B3-9724-440A-8361-(E-Mail Removed)...
> Nick,
>
> Thank you for your input. The 3rd party tool to convert to a graphic is
> probably not an option as we would have to purchase licenses for an
> enterprise application.
>
> I will continue to pursue a VBA solution.
> In C# (webapp) the code was:
>
> // Get a ref to a PostedFile object
> HttpPostedFile postedFile = myFile.PostedFile;
>
> //Get size of uploaded file
> int nFileLen = postedFile.ContentLength;
>
> string fileNameFullPath = postedFile.FileName;
> string filename = Path.GetFileName(fileNameFullPath);
> //Allocate an byte array to store the data from the file

uploaded
> byte[] myData = new byte[nFileLen];
> // setup SQL access (connection info omitted)
> addEmp.Parameters.Add("@excel_workbook", SqlDbType.Image,
> myData.Length).Value = myData;
>
>
> Karla
>
>
> "NickHK" wrote:
>
> > Karla,
> > You cannot convert a WB to an image, but you can Copy/Paste Special a

range
> > as a picture.
> > However, on my systems, you are limited to relatively small ranges.
> > You would still have to get the picture out of Excel and into a suitable
> > graphics format, either in memory or on disk, before you can send the

bytes
> > to the DB.
> >
> > If you could do it in C++, something similar in VB/VBA will (probably)
> > exist. Depends how you did it ?
> >
> > It would be easier to install a <printer> that can convert to a graphic.
> > Possibly:
> >

http://www.print-driver.com/howto/co...le_to_jpeg.htm
> >
> > NickHK
> >
> > "Karla" <(E-Mail Removed)> wrote in message
> > news:0A1C18EF-6CDC-474E-A219-(E-Mail Removed)...
> > > Our User group would like a button in an Excel workbook that saves a

copy
> > of
> > > the workbook in MSSQL database. We have done something similiar in a

Web
> > app
> > > using C#. The excel workbook is stored in MSSQL db as an image. That

app
> > has
> > > access to the workbook as a saved file, not as an active workbook

during
> > that
> > > process. Converts the file to byte then image.
> > >
> > > I can't duplicate the process successfully in VBA code. The workbook

> > object
> > > doesn't seem to support the Savepicture or CopyAsPicture functions.

In
> > order
> > > to use the byte conversion I need the Length of the file(workbook),

> > another
> > > property I am unable to use with the workbook object.
> > >
> > > Any help would be appreciated. I am using VBA 6.3. Thanks.
> > >
> > >

> >
> >
> >



 
Reply With Quote
 
=?Utf-8?B?S2FybGE=?=
Guest
Posts: n/a
 
      19th Mar 2007
Nick,
I am not certain that a virtual printer conversion is a viable solution as I
would have to deploy and install it for all the users of the Excel workbook.
The Excel workbook runs on their local machines not a server type setup.

Karla

"NickHK" wrote:

> Karla,
> If it is licensing issue on that component that you use already, then it is
> irrelevant.
> Install a virtual printer that output in the desired image format, or one
> the many freely available PDF printers.
>
> NickHK
>
> "Karla" <(E-Mail Removed)> wrote in message
> news:89FAD4B3-9724-440A-8361-(E-Mail Removed)...
> > Nick,
> >
> > Thank you for your input. The 3rd party tool to convert to a graphic is
> > probably not an option as we would have to purchase licenses for an
> > enterprise application.
> >
> > I will continue to pursue a VBA solution.
> > In C# (webapp) the code was:
> >
> > // Get a ref to a PostedFile object
> > HttpPostedFile postedFile = myFile.PostedFile;
> >
> > //Get size of uploaded file
> > int nFileLen = postedFile.ContentLength;
> >
> > string fileNameFullPath = postedFile.FileName;
> > string filename = Path.GetFileName(fileNameFullPath);
> > //Allocate an byte array to store the data from the file

> uploaded
> > byte[] myData = new byte[nFileLen];
> > // setup SQL access (connection info omitted)
> > addEmp.Parameters.Add("@excel_workbook", SqlDbType.Image,
> > myData.Length).Value = myData;
> >
> >
> > Karla
> >
> >
> > "NickHK" wrote:
> >
> > > Karla,
> > > You cannot convert a WB to an image, but you can Copy/Paste Special a

> range
> > > as a picture.
> > > However, on my systems, you are limited to relatively small ranges.
> > > You would still have to get the picture out of Excel and into a suitable
> > > graphics format, either in memory or on disk, before you can send the

> bytes
> > > to the DB.
> > >
> > > If you could do it in C++, something similar in VB/VBA will (probably)
> > > exist. Depends how you did it ?
> > >
> > > It would be easier to install a <printer> that can convert to a graphic.
> > > Possibly:
> > >

> http://www.print-driver.com/howto/co...le_to_jpeg.htm
> > >
> > > NickHK
> > >
> > > "Karla" <(E-Mail Removed)> wrote in message
> > > news:0A1C18EF-6CDC-474E-A219-(E-Mail Removed)...
> > > > Our User group would like a button in an Excel workbook that saves a

> copy
> > > of
> > > > the workbook in MSSQL database. We have done something similiar in a

> Web
> > > app
> > > > using C#. The excel workbook is stored in MSSQL db as an image. That

> app
> > > has
> > > > access to the workbook as a saved file, not as an active workbook

> during
> > > that
> > > > process. Converts the file to byte then image.
> > > >
> > > > I can't duplicate the process successfully in VBA code. The workbook
> > > object
> > > > doesn't seem to support the Savepicture or CopyAsPicture functions.

> In
> > > order
> > > > to use the byte conversion I need the Length of the file(workbook),
> > > another
> > > > property I am unable to use with the workbook object.
> > > >
> > > > Any help would be appreciated. I am using VBA 6.3. Thanks.
> > > >
> > > >
> > >
> > >
> > >

>
>
>

 
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
Copy Data from Excel 2007 XLSM workbook to Excel 2003 XLS workbook using ADO Andy Microsoft Excel Programming 2 27th Jul 2007 10:44 PM
Trying to use VBA to save a copy of a workbook =?Utf-8?B?a2ZlbGw=?= Microsoft Excel Misc 2 23rd Mar 2007 12:36 PM
Save copy of workbook =?Utf-8?B?TWFybmll?= Microsoft Excel Programming 6 20th Oct 2006 01:59 PM
Using interop.excel to open a workbook, the workbook doesn't ask to save changes. milmans@gmail.com Microsoft Excel Programming 1 28th Dec 2005 10:23 PM
How can I save an editable copy of a protected excel workbook? =?Utf-8?B?cmFuZHlpY2U=?= Microsoft Excel Misc 1 23rd Dec 2004 09:01 PM


Features
 

Advertising
 

Newsgroups
 


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