+ Reply to Thread
Results 1 to 4 of 4

How do I go about passing a custom class object from Excel to Word?

Hybrid View

AnthonyGFS How do I go about passing a... 03-28-2018, 08:07 PM
6StringJazzer Re: How do I go about passing... 03-28-2018, 08:14 PM
AnthonyGFS Re: How do I go about passing... 03-28-2018, 10:28 PM
6StringJazzer Re: How do I go about passing... 03-29-2018, 07:40 AM
  1. #1
    Registered User
    Join Date
    04-28-2017
    Location
    Sydney, Australia
    MS-Off Ver
    2016
    Posts
    14

    How do I go about passing a custom class object from Excel to Word?

    Hey all,

    I have an excel sheet that I use to put together costings, and to do this I put all of the variable costs into a UserForm and with the help of a custom class object I created, it is distributed into the relevant cells.

    After I have finished in excel, I want to pass my object to Microsoft Word so I can easily transfer the data in one variable. I cannot seem to find any guides online or any help anywhere that tells me how to do this. I have tried multiple avenues, but the closest I have gotten is to create a variable that represents the excel sheet, and that's about it.

    Can anyone offer any advice on how I can pass custom objects between Microsoft Applications?

    Thanks in advance!

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,995

    Re: How do I go about passing a custom class object from Excel to Word?

    What do you want to do with it once it is available to Word? I think you may want to instantiate Word in your Excel macro and do the work in the same macro, still in Excel.

    It would help to have more detail about your Excel code, and any code you may have in Word.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    04-28-2017
    Location
    Sydney, Australia
    MS-Off Ver
    2016
    Posts
    14

    Re: How do I go about passing a custom class object from Excel to Word?

    Hi Jeff,

    I work for a construction company so my custom class is a breakdown of all of a Granny Flat's inclusions. For example, I would start with
     Dim gf as GRANNYFLAT
    Set gf = new GRANNYFLAT
    and then it's properties are sorted into major components, smaller components of those major components, then each property has a Value (essentially a quantity), a Cost, a Description and a Unit of Measurement (all strings and integers). Essentially, I would be using the quantity, description and sometimes the cost of each property in the word document to complete my quote.

    At the moment, all I have in Word are text form fields that I would be inputting this data into.

    Now that you mention it, I can't believe I didn't think to instantiate Word in excel and just do it through excel, so I will try that! However, just for my knowledge and curiosity I guess, is there a way I can pass a custom object between Microsoft Applications?

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,995

    Re: How do I go about passing a custom class object from Excel to Word?

    There is no built-in way to pass an object between applications if you are not running both applications from the same VBA project. I know of no mechanism for communication between two separate running VBA processes.

    Another solution to this is to serialize the object. This is [URL="https://docs.oracle.com/javase/tutorial/jndi/objects/serial.html"]supported directly in Java[/URL] but not VBA. Serializing outputs the object's state as a text file. You would need to build a Serialize method that would create a text file with the data written in some format. If your object is just a flat set of variables then it could be something like one value per line. (If you have more complex data structures, like arrays or trees, then it is still straightforward but not trivial.) Then another Deserialize method would read the file and create an object from it. You would have to have the same class declared in both your Excel and Word VBA projects. You could just copy and paste the code, or you could Export it from one project and Import it to the other.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 05-25-2016, 12:24 PM
  2. [SOLVED] Passing combobox value to custom class
    By Jacques Grobler in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 07-05-2012, 05:49 AM
  3. Passing combobox value to custom class
    By Jacques Grobler in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-04-2012, 06:13 AM
  4. Excel to Word passing data dynamically with bookmarks from Excel to Word
    By csekhar.apps in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-10-2010, 09:52 AM
  5. [SOLVED] Passing a .NET DataSet object to Excel to be used with VBA
    By Teddy Sohnrey in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-17-2006, 07:10 AM
  6. [SOLVED] Object class in Excel VBA
    By Tom Chau in forum Excel General
    Replies: 1
    Last Post: 06-29-2006, 06:29 AM
  7. Passing Custom Class Variables through Functions
    By Xiazer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-19-2006, 12:34 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1