Results 1 to 8 of 8
  1. #1
    New Lounger
    Join Date
    Mar 2003
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: document.saveas - want to create a folder (VBA/Word 2000)

    I have created my word automation object, set the application.visible to false and I can save the document to the default MyDocuments folder. I would like to create a folder under the MyDocuments folder and then save the word document there. I need some help because my code below does not work. I tried using the "" and it just gets ignored and the foldername and filename are concatenated and saved in the MyDocuments folder. Also, how can I create a folder in a location other than under the MyDocuments default folder? TIA

    JU

    function startWord(strFile)
    {
    var myApp = new ActiveXObject("Word.Application");

    if (myApp != null)
    {
    //Open word on the client machine in the background
    myApp.Visible = false;

    //Pass the URL for word to open the document
    var worddoc = myApp.Documents.Open(strFile);

    //Save the document in a new folder under the default folder of MyDocuments
    worddoc.SaveAs("testfoldertestdoc.doc", 0); //Here it just ignores the slash and concatenates the name

    //Close the word app
    myApp.quit();
    }

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: document.saveas - want to create a folder (VBA/Word 2000)

    Ah! Another .Netter, VB variety...

    You are creating a COM addin, no?

    Add the System.IO namespace and try this passing in the fullpath to the
    folder. Nice thing about this .net method (if I remember correctly) -- it creates
    the entire path even if the root does not exist. Sorry, you'll have to translate from
    this C# to VB.net

    public static bool MakeFolder(string fullName)
    {
    try
    {
    DirectoryInfo folder = new DirectoryInfo(fullName);
    if (! folder.Exists)
    folder.Create();
    return true;
    }
    catch
    {
    //Some kind of directory error (permissions??)
    return false;
    }
    }
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: document.saveas - want to create a folder (VBA/Word 2000)

    What language is that? JavaScript, or as Kevin surmises, something newer? The syntax you are using will use either Word's default document path at startup, or the last "save" path used by the user, or the path from which you opened the document (I'm never positive which it will be). You can, of course specify an exact path (c:myAppwhatever.doc) but it's possible that you have to double the to get them recognized in your programming language if it normally understands the to be an "escape the following" character.

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: document.saveas - want to create a folder (VBA/Word 2000)

    That might be Java, but it ain't VB.Net.

    If it's the former, the DirectoryInfo equivalents should be available by creating an instance of Scripting.FileSystemObject.

    Gary

  5. #5
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: document.saveas - want to create a folder (VBA/Word 2000)

    Silly me. But now that Iook at it, there's no way that's VB.net.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  6. #6
    New Lounger
    Join Date
    Mar 2003
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: document.saveas - want to create a folder (VBA/Word 2000)

    It is JavaScript or JScript since I create an activexobject which allows me to get a handle on an automation object, in this case it is Word. Once I get a handle on Word, I can use the VBA object model to do things in word. However, I have found saving the word document to a specific directory challenging. Per my understanding from the Object Browser help in MS Word, there are different default paths for different file formats which is accessed via the application.options.DefaultFilePath(Path) property. Path is a long which is required and is one of the wdDefaultFilePath constants that represents word documents, graphics, templates, etc. The documentation also states that it is a read/write property. My issue is that when I try to write this in javascript, my javascript editor says that I am doing an illegal assignment on the left hand side, a syntax error:

    ex. myApp.Options.DefaultFilePath(wdDocumentsPath) = "c:testfolder"

    The editor does not like the parentheses. If I change to square brackets, the editor allows me to save but then I do not change the DefaultFilePath and the doc saves in the default folder of my documents. I was able to save a file below the my documents folder via document.saveas() as long as the folder already exists. Ex.
    If I do document.saveas("testfoldertest.doc"), it saves the folder if the testfolder exists(which I can check for and create using the file system object) under my documents(the default path). I still have not figured how to save to a directory other than the my documents however and it appears I hit a wall with the documentation as I described above. Is there another way that I have missed? TIA

  7. #7
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: document.saveas - want to create a folder (VBA/Word 2000)

    There are a couple of things you could try.

    The default path is stored in the registry. Perhaps you could try seting the value there instead. For Word 97 the registry key is Doc-Path in [HKEY_CURRENT_USERSoftwareMicrosoftOffice8.0WordOpt ions]
    You may discover that changing this setting doesn't immediately take if Word is already open

    If you don't actually want to change the users default path then you can use the string in front of the file names you are using. The default path only sets where the file would go if you don't provide the full path in the save string.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  8. #8
    New Lounger
    Join Date
    Mar 2003
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: document.saveas - want to create a folder (VBA/Word 2000)

    Got it. Silly Mistake. When I do document.saveas(), I need to check for two things

    1)That the folder does exist and
    2)(Here's the silly mistake) Make sure I use the "" for "". When I was using the string "C:testfolder" in the document.saveas it was not working because I needed to use "C:testfolder"

    Thanks everyone for your help

Posting Permissions

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