+ Reply to Thread
Results 1 to 7 of 7

Excel Export to OLE Object with user prompted SaveAs HELP

  1. #1
    Registered User
    Join Date
    07-02-2013
    Location
    JEwland
    MS-Off Ver
    Excel 2010
    Posts
    6

    Excel Export to OLE Object with user prompted SaveAs HELP

    First of all, I am a novice here with Excel and have learned much with the resources here. I have stuck on a VBA script I have been working on that takes excel data and inputs them into an word document template that is embedded into the workbook. It utilizes bookmarks in the document template to reference locations where the data should be input.

    I started very simple with this code that simply uses word to open the embedded document and SaveAs with user prompted save location:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    This code WAS working and would open the OLE in Word and prompt the user where to SaveAs and file name. Now for whatever reason it errors on [.Name = "c:\SaveExample.doc"] line saying the object doesn't support the property or method.



    My full code is:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    What it is supposed to do is 1) Open the embedded .dotx OLE object and 2) using Word.Bookmarks insert data from cells on my spreadsheet into this new word document that it has created and 3) provide the user with a Save As dialog prompt so they can specify save locaiton and file name.

    I am sure my coding is way off and please forgive my beginnerness but I am in need of the expert's help on this one. If anyone could help me correct my code I would be greatly indebted! Thank you.

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Excel Export to OLE Object with user prompted SaveAs HELP

    Welcome to the forum!

    When you Compile it, as I often recommend, you can see the problem is your Word constant wdDialogFileSaveAs. Set that variable = 84 if you are only going to use early binding to the Word object.

    Tip: In MSWord's VBE's Immediate Window, type, ?wdDialogFileSaveAs and press enter key to get the value.

  3. #3
    Registered User
    Join Date
    07-02-2013
    Location
    JEwland
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Excel Export to OLE Object with user prompted SaveAs HELP

    Thank you for the guidence.

    Now my final questions is: How can I modify this code so that the embedded DOTX is not changed? The report is generated and a user can save a copy of the report however, I need the embedded DOTX to remain unchanged. Anyone have any code that can help me achieve this?


    My fixed code is:

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Last edited by leemanx; 07-23-2013 at 12:11 PM.

  4. #4
    Registered User
    Join Date
    07-02-2013
    Location
    JEwland
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Excel Export to OLE Object with user prompted SaveAs HELP

    Ok, I have a crude but usable solution which involves copying my embedded Dotx to another sheet and using that to work the data then deleting it when done, thus preserving the original Dotx.

    It works, however, if you try to run the macro a second time it errors with "Error 462 The remote server machine does not exist or is unavailble" on line With Word.Application.Dialogs(84)

    If I click my macro again it works, so effectively it runs sucessfully every other time you run it. Anyone with any insight on why that is?

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  5. #5
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Excel Export to OLE Object with user prompted SaveAs HELP

    Have you tried making the embeded object a template?

    I don't have time to test this right now but try this. SaveAs first after you open the oleobject. Then set the object to nothing. Make your changes to the Word file and then Save. You may have to set the Word object to Nothing and then reset the reference to the Word object based on the filename saved with a GetObject("c:\path\whatever.docx"). I can test these late tonight if needed.

  6. #6
    Registered User
    Join Date
    07-02-2013
    Location
    JEwland
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Excel Export to OLE Object with user prompted SaveAs HELP

    Alright, I have my solution which seems to be working well. With your advice I decided that it would simply save my ole to C:/ as a working copy, perform its bookmark merges and then save as with dialog. This has worked exactly as I need it to with the exception that the macro fails every other time it is ran.

    It errors on "Set wrdApp = Word.Application" with Error 462 The remote server machine does not exist or is unavailble.

    I'm certain I am missing a minor detail in the code that it causing this. It will work if I try and run it again but I can't have it erroring out every other time it is ran.

    Thanks so far Kenneth, if you have any additional help you could give to solve this last issue, I will be set and very appreciative!


    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Last edited by leemanx; 07-23-2013 at 06:22 PM.

  7. #7
    Registered User
    Join Date
    07-02-2013
    Location
    JEwland
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Excel Export to OLE Object with user prompted SaveAs HELP

    Bump

    Anyone have insight as to this error occuring every other time the macro is ran?

+ 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. VBA to prompted user for employee number.
    By Absent in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 01-27-2012, 05:53 PM
  2. Export Sheet into xls format without SaveAs
    By mushman1 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-23-2009, 10:16 PM
  3. [SOLVED] not being prompted that user has file open
    By maryj in forum Excel General
    Replies: 0
    Last Post: 12-15-2005, 11:15 AM
  4. Replies: 0
    Last Post: 05-23-2005, 09:03 AM
  5. Export Sql data to Excel with ADO in VB6 without using the object model
    By poppy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-23-2005, 07:48 AM

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