+ Reply to Thread
Results 1 to 5 of 5

Name and Save Document Using Defined Variables

  1. #1
    Registered User
    Join Date
    05-01-2009
    Location
    Seattle
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    21

    Name and Save Document Using Defined Variables

    Hi everyone, I wasn't sure if I should put this question under "Excel Programing" or "Word Programing"... I am writing this program in excel, but the program references the word object library.

    WHAT I AM TRYING TO DO: This program I'm making defines variables based on the values of a couple specfic cells. I want to save a newly created word document that this program generates, using the variables as its name.

    FOR EXAMPLE:

    Please Login or Register  to view this content.
    I thought that this might work, as it has with other things such as this:

    Please Login or Register  to view this content.
    Any help is appreciated!

    odo-
    Last edited by odo; 05-29-2009 at 02:47 PM.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Name and Save Document Using Defined Variables

    Activedocument is a Word only object. It would work if you were writing the code in Word as it would be part of Word's Application object.

    You can use Activedocument in Excel but only through an object which references the Word application.

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    05-01-2009
    Location
    Seattle
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    21

    Re: Name and Save Document Using Defined Variables

    Andy Pope,

    Thanks for your help changing the "+" to "&" did the trick. Instead of doing that for the document name though, I just declared a variable with all the formating done first and used that to name the document. however as I fixed that issue, I ran into another issue. The document isn't saving into the right place. I want it to save to "C:\Announce\BE", but its saving to "my documents" folder.. Why is that? Before I use to just name the document "test.doc" and it would save in the right place, now the name is correct but the location it saves to isn't ah.. Here is my code:

    Please Login or Register  to view this content.
    also, what is the hotkey to format all your code and make it look nice?

    odo-

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Name and Save Document Using Defined Variables

    I can only assume your routine ChangeFileOpenDirectory is not working properly.

    With no path specified the file will be written to the active folder, which is the last one you browser to within the application. If you have not changed directory then the default starting folder will be used.

    Simplest thing is to prefix the file name with the path when saving.

  5. #5
    Registered User
    Join Date
    05-01-2009
    Location
    Seattle
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    21

    Re: Name and Save Document Using Defined Variables

    I found out what was wrong, it was a simple syntax error in the code:

    Mistake:

    Please Login or Register  to view this content.
    Correct:

    Please Login or Register  to view this content.
    Simple as that, more can be read here: MSDN

    Andy Pope, thanks again for all your help

    SOLVED!

    odo-

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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