Contact from VS C++ to Excel VBA




















  1. #1


    Contact from VS C++ to Excel VBA

    I’ve got an app written in Visual Studio C++ that deals with excel lines of data and presents it in a Form.

    I now need to print the data. A while back I wrote this app in VBA and printing was a simple task of calling UserForm1.Print

    How can I get my C++ app to call up this UserForm1 and call that UserForm1.Print command?

    Once I get the connection between these two entities I can send the data I want printed and let VBA do the print work.

    How does my C++ talk to my Excel VBA?

    Thanks for anything

    Klatau Broada Nektau





  2. #2


    Re: Contact from VS C++ to Excel VBA

    Are you using an excel automaton in your VC++ code?

    Victor Nijegorodov





  3. #3


    Re: Contact from VS C++ to Excel VBA

    I don’t know what excel automation is.
    I learned C++ in the 1970s, really.
    I use a third party software “libxl” to read cells write cells and open/save workbooks/sheets.

    Klatau Broada Nektau





  4. #4


    Re: Contact from VS C++ to Excel VBA

    Quote Originally Posted by Albatross
    View Post

    I don’t know what excel automation is.

    How to automate Excel from C++ without using MFC or #import
    How to automate Excel from MFC and Visual C++ 2005 or Visual C++ .NET to fill or obtain data in a range using arrays

    Quote Originally Posted by Albatross
    View Post

    I use a third party software “libxl” to read cells write cells and open/save workbooks/sheets.

    Doesn’t this “libxl” have a Print function?

    Victor Nijegorodov





  5. #5


    Re: Contact from VS C++ to Excel VBA

    I found a solution which is much, much easier than what your links put me into.
    Going to the links you offered I was shocked at the complexity involved when this excel automation philosophy was involved.
    And my intention was to print a WinForm, not an excel sheet. The excel files serve as a database.
    When my client is satisfied with this I’ll see how that complex philosophy really works.

    Code:

    System::Void BhMainForm::pbPrint_Click(System::Object^ sender, System::EventArgs^ e) {
    
    	Graphics^ myGraphics = BhMainForm::CreateGraphics();
    
    	System::Drawing::Size size = this->Size;
    
    	BhMainForm::memoryImage = gcnew Bitmap(size.Width, size.Height, myGraphics);
    	Graphics^ memoryGraphics = myGraphics->FromImage(memoryImage);
    
    	int locX = this->Location.X + 220;
    	int locY = this->Location.Y + 28;
    	size.Width = size.Width - 225;
    	size.Height = size.Height - 32;
    
    	memoryGraphics->CopyFromScreen(locX, locY, 0, 0, size);
    
    	printDocument1->DefaultPageSettings->Landscape = true;
    
    	printDocument1->Print();
    
    } // System::Void BhMainForm::pbPrint_Click(System::Object^ sender, System::EventArgs^ e)

    Klatau Broada Nektau





  6. #6


    Re: Contact from VS C++ to Excel VBA

    Quote Originally Posted by Albatross
    View Post

    I found a solution which is much, much easier than what your links put me into.
    Going to the links you offered I was shocked at the complexity involved when this excel automation philosophy was involved.

    However this solution has nothing to do with the native VC++ and this Forum.
    Your code is C++/CLI, ie the managed code.

    Victor Nijegorodov


















Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts












Click Here to Expand Forum to Full Width














.

Leave a Comment